// Module defining this command // Optional custom code for this activity /// <summary> /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run. /// </summary> /// <param name="context">The NativeActivityContext for the currently running activity.</param> /// <returns>A populated instance of Sytem.Management.Automation.PowerShell</returns> /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks> protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context) { System.Management.Automation.PowerShell invoker = global::System.Management.Automation.PowerShell.Create(); System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName); // Initialize the arguments if (FilePath.Expression != null) { targetCommand.AddParameter("FilePath", FilePath.Get(context)); } if (ArgumentList.Expression != null) { targetCommand.AddParameter("ArgumentList", ArgumentList.Get(context)); } if (Credential.Expression != null) { targetCommand.AddParameter("Credential", Credential.Get(context)); } if (WorkingDirectory.Expression != null) { targetCommand.AddParameter("WorkingDirectory", WorkingDirectory.Get(context)); } if (LoadUserProfile.Expression != null) { targetCommand.AddParameter("LoadUserProfile", LoadUserProfile.Get(context)); } if (NoNewWindow.Expression != null) { targetCommand.AddParameter("NoNewWindow", NoNewWindow.Get(context)); } if (PassThru.Expression != null) { targetCommand.AddParameter("PassThru", PassThru.Get(context)); } if (RedirectStandardError.Expression != null) { targetCommand.AddParameter("RedirectStandardError", RedirectStandardError.Get(context)); } if (RedirectStandardInput.Expression != null) { targetCommand.AddParameter("RedirectStandardInput", RedirectStandardInput.Get(context)); } if (RedirectStandardOutput.Expression != null) { targetCommand.AddParameter("RedirectStandardOutput", RedirectStandardOutput.Get(context)); } if (Verb.Expression != null) { targetCommand.AddParameter("Verb", Verb.Get(context)); } if (WindowStyle.Expression != null) { targetCommand.AddParameter("WindowStyle", WindowStyle.Get(context)); } if (Wait.Expression != null) { targetCommand.AddParameter("Wait", Wait.Get(context)); } if (UseNewEnvironment.Expression != null) { targetCommand.AddParameter("UseNewEnvironment", UseNewEnvironment.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }