public void TestMethod1()
        {
            var client = new PowerShellClient();

            var response = client.ExecuteCommand("git --version");

            Assert.AreEqual(response, "git version 1.9.4.msysgit.2");
        }
        public static void Run()
        {
            var userName = "******";
            var password = "******";

            try
            {
                // Create a connector
                var connector = new ActiveDirectoryConnector(userName, password);

                // Initialze Powershell Client
                using (var client = PowerShellClient.Create(connector))
                {
                    // Create Command
                    var geUserCommand = new PowershellCommand
                    {
                        Name              = "GetUser",
                        CommandText       = "Get-User",
                        CommandParameters = new List <PowershellCommandParameter> {
                            new PowershellCommandParameter {
                                Name = "ResultSize", Value = "unlimited"
                            },                                                                                   //"100"
                            new PowershellCommandParameter {
                                Name = "OrganizationalUnit", Value = "Marketing"
                            }
                        }
                    };

                    // Execute Command
                    var result = client.Execute <ActiveDirectory>(new List <PowershellCommand> {
                        geUserCommand
                    });

                    // Success, get the data
                    if (result.Status == StatusCode.SUCCESS)
                    {
                        var adUsers = result.Content;

                        Console.WriteLine($"{adUsers.Count} users found");
                    }
                    else // Failes show the errors
                    {
                        Console.WriteLine(result.Status);
                        Console.WriteLine(result.StatusText);
                        Console.WriteLine(result.Errors);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 3
0
        public void TestExecutePSScriptSuccess()
        {
            var scriptFile = "";
            var connector  = new FileConnector(new FileStream(scriptFile, FileMode.Open));

            using (var client = PowerShellClient.Create(connector))
            {
                var result = client.ExecuteNonQuery(
                    new List <PowershellCommand>
                {
                    new PowershellCommand {
                        IsScript = true, CommandText = connector.ScriptText
                    }
                });

                Assert.Equals(result.Status, StatusCode.SUCCESS);
            }
        }