protected PsGetCommandBase() : base() { Invoker = new PowerShellInvoker(this); HostEnvironment = new PowerShellHostEnvironment(this); Session = new PowerShellSession(this); PathService = new PowerShellPathService(this); }
public void Invoke_WorkingDirectory_InvokesFromWorkingDirectory() { var workingDirectory = Directory.CreateDirectory(Guid.NewGuid().ToString()); _invoker = new PowerShellInvoker(workingDirectory.FullName); try { var result = _invoker.Invoke("Get-Location"); Assert.AreEqual(1, result.Count, "Get-Location should return a single result"); Assert.AreEqual(workingDirectory.FullName, result.Single().BaseObject.ToString()); } finally { Directory.Delete(workingDirectory.FullName); } }
private static PSModuleInfo GetModuleInfo( string modulePath, string secretMgtModulePath, out ErrorRecord error) { // Get module information by loading it. var results = PowerShellInvoker.InvokeScript <PSModuleInfo>( script: @" param ([string] $ModulePath, [string] $SecretMgtModulePath) # ModulePath module may have a dependency on SecretManagement module, # so make sure it is loaded. $null = Import-Module -Name $SecretMgtModulePath -ErrorAction SilentlyContinue Import-Module -Name $ModulePath -PassThru ", args: new object[] { modulePath, secretMgtModulePath }, out error); return((results.Count == 1) ? results[0] : null); }
public void Execute(TaskStep task) { var inputs = new Dictionary <string, object>(); foreach (var input in task.Inputs) { inputs.Add($"{input.Key}", input.Value); } var taskVariables = CreateTaskVariables(); var variables = new Dictionary <string, object>(); foreach (var item in inputs) { variables.Add("INPUT_" + item.Key.Replace(' ', '_').ToUpperInvariant(), item.Value); } foreach (var item in taskVariables) { variables.Add(item.Key.Replace(".", "_"), item.Value); } var scriptName = task.TaskDefinition.Execution["PowerShell3"]["target"].ToString(); string scriptToRun = Path.Combine(task.TaskTargetFolder, scriptName); var timeout = task.TimeoutInMinutes * 60 * 1000; PowerShellInvoker.RunPowerShellScript( scriptToRun, task.TaskTargetFolder, null, variables, timeout: timeout == 0 ? -1 : timeout); }
public void SetUp() => _invoker = new PowerShellInvoker(TestContext.CurrentContext.WorkDirectory);