protected override void ProcessRecord() { ServiceController[] _services = ServiceController.GetServices(); foreach (String _name in Name) { foreach (ServiceController _service in _services) { if (_service.ServiceName == _name) { try { _service.Start(); } // Mimic PowerShell's lack of reporting error when process is already started. catch (Exception) { } _service.WaitForStatus(ServiceControllerStatus.Running); if (PassThru.ToBool()) { WriteObject(_service); } } } } }
protected override void ProcessRecord() { ServiceController[] _services = ServiceController.GetServices(); foreach (String _name in Name) { foreach (ServiceController _service in _services) { if ((_service.ServiceName == _name) && (_service.CanPauseAndContinue)) { if (!Force.ToBool()) { if (_service.DependentServices.Length != 0) { WriteError(new ErrorRecord(new InvalidOperationException("Cannot suspend service \"" + _service.ServiceName + "\" because other services are dependent on it. Use -Force to override."), "ServiceHasDependentServices", ErrorCategory.InvalidOperation, _service)); } else { _service.Pause(); } } else { _service.Pause(); } _service.WaitForStatus(ServiceControllerStatus.Paused); if (PassThru.ToBool()) { WriteObject(_service); } } } } }
protected override void ProcessRecord() { // TODO: deal with Force // TODO: deal with ShouldProcess PSVariable variable = new PSVariable(Name, Value, Option); if (Description != null) { variable.Description = Description; } //TODO: check if variable already exists and check if force has influence on behavior //implement also an overloaded Get method in PSVariableIntrniscs that allow to pass a scope try { //TODO: create a new overloaded method in PSVariableIntrinsics that allows to pass (bool)this.Force SessionState.PSVariable.Set(variable); } catch (Exception ex) { WriteError(new ErrorRecord(ex, "", ErrorCategory.InvalidOperation, variable)); return; } if (PassThru.ToBool()) { WriteObject(variable); } }
protected override void ProcessRecord() { // TODO: deal with scope // TODO: deal with Force // TODO: deal with ShouldProcess PSVariable variable = new PSVariable(Name, Value, Option); if (Description != null) { variable.Description = Description; } try { SessionState.SessionStateGlobal.NewVariable(variable, (bool)this.Force); } catch (Exception ex) { WriteError(new ErrorRecord(ex, "", ErrorCategory.InvalidOperation, variable)); return; } if (PassThru.ToBool()) { WriteObject(variable); } }
// 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 (PassThru.Expression != null) { targetCommand.AddParameter("PassThru", PassThru.Get(context)); } if (DomainCredential.Expression != null) { targetCommand.AddParameter("DomainCredential", DomainCredential.Get(context)); } if (LocalCredential.Expression != null) { targetCommand.AddParameter("LocalCredential", LocalCredential.Get(context)); } if (NewName.Expression != null) { targetCommand.AddParameter("NewName", NewName.Get(context)); } if (Force.Expression != null) { targetCommand.AddParameter("Force", Force.Get(context)); } if (Restart.Expression != null) { targetCommand.AddParameter("Restart", Restart.Get(context)); } if (WsmanAuthentication.Expression != null) { targetCommand.AddParameter("WsmanAuthentication", WsmanAuthentication.Get(context)); } if (Protocol.Expression != null) { targetCommand.AddParameter("Protocol", Protocol.Get(context)); } if (GetIsComputerNameSpecified(context) && (PSRemotingBehavior.Get(context) == RemotingBehavior.Custom)) { targetCommand.AddParameter("ComputerName", PSComputerName.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }
// 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 System.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 (Path.Expression != null) { targetCommand.AddParameter("Path", Path.Get(context)); } if (LiteralPath.Expression != null) { targetCommand.AddParameter("LiteralPath", LiteralPath.Get(context)); } if (Name.Expression != null) { targetCommand.AddParameter("Name", Name.Get(context)); } if (PassThru.Expression != null) { targetCommand.AddParameter("PassThru", PassThru.Get(context)); } if (Force.Expression != null) { targetCommand.AddParameter("Force", Force.Get(context)); } if (Filter.Expression != null) { targetCommand.AddParameter("Filter", Filter.Get(context)); } if (Include.Expression != null) { targetCommand.AddParameter("Include", Include.Get(context)); } if (Exclude.Expression != null) { targetCommand.AddParameter("Exclude", Exclude.Get(context)); } if (Credential.Expression != null) { targetCommand.AddParameter("Credential", Credential.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }
// 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 (ReferenceObject.Expression != null) { targetCommand.AddParameter("ReferenceObject", ReferenceObject.Get(context)); } if (DifferenceObject.Expression != null) { targetCommand.AddParameter("DifferenceObject", DifferenceObject.Get(context)); } if (SyncWindow.Expression != null) { targetCommand.AddParameter("SyncWindow", SyncWindow.Get(context)); } if (Property.Expression != null) { targetCommand.AddParameter("Property", Property.Get(context)); } if (ExcludeDifferent.Expression != null) { targetCommand.AddParameter("ExcludeDifferent", ExcludeDifferent.Get(context)); } if (IncludeEqual.Expression != null) { targetCommand.AddParameter("IncludeEqual", IncludeEqual.Get(context)); } if (PassThru.Expression != null) { targetCommand.AddParameter("PassThru", PassThru.Get(context)); } if (Culture.Expression != null) { targetCommand.AddParameter("Culture", Culture.Get(context)); } if (CaseSensitive.Expression != null) { targetCommand.AddParameter("CaseSensitive", CaseSensitive.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }
protected override void ProcessRecord() { InvokeProvider.Item.Rename(Path, NewName); if (PassThru.ToBool()) { WriteObject(Path); } }
protected override void ProcessRecord() { ServiceController[] _services = ServiceController.GetServices(); foreach (String _name in Name) { foreach (ServiceController _service in _services) { if (_service.ServiceName.ToLower() == _name.ToLower()) { if (!_service.CanStop) { WriteError(new ErrorRecord( new InvalidOperationException( "Cannot stop service \"" + _service.ServiceName + "\". The service might be an important service or may be in an unresponsive state."), "ServiceCanNotStop", ErrorCategory.InvalidOperation, _service)); continue; } if (!Force.ToBool()) { if (_service.DependentServices.Length != 0) { WriteError(new ErrorRecord( new InvalidOperationException( "Cannot stop service \"" + _service.ServiceName + "\" because other services are dependent on it. Use -Force to override."), "ServiceHasDependentServices", ErrorCategory.InvalidOperation, _service)); } else { _service.Stop(); } } else { _service.Stop(); } _service.WaitForStatus(ServiceControllerStatus.Stopped); if (PassThru.ToBool()) { WriteObject(_service); } } } } }
// 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 System.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 (Name.Expression != null) { targetCommand.AddParameter("Name", Name.Get(context)); } if (ServiceDisplayName.Expression != null) { targetCommand.AddParameter("DisplayName", ServiceDisplayName.Get(context)); } if (Description.Expression != null) { targetCommand.AddParameter("Description", Description.Get(context)); } if (StartupType.Expression != null) { targetCommand.AddParameter("StartupType", StartupType.Get(context)); } if (Status.Expression != null) { targetCommand.AddParameter("Status", Status.Get(context)); } if (InputObject.Expression != null) { targetCommand.AddParameter("InputObject", InputObject.Get(context)); } if (PassThru.Expression != null) { targetCommand.AddParameter("PassThru", PassThru.Get(context)); } if (GetIsComputerNameSpecified(context) && (PSRemotingBehavior.Get(context) == RemotingBehavior.Custom)) { targetCommand.AddParameter("ComputerName", PSComputerName.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }
protected override void ProcessRecord() { foreach (String _path in Path) { InvokeProvider.Item.Move(_path, Destination); if (PassThru.ToBool()) { WriteObject(Path); } } }
// 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 System.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 (Force.Expression != null) { targetCommand.AddParameter("Force", Force.Get(context)); } if (NoWait.Expression != null) { targetCommand.AddParameter("NoWait", NoWait.Get(context)); } if (Name.Expression != null) { targetCommand.AddParameter("Name", Name.Get(context)); } if (InputObject.Expression != null) { targetCommand.AddParameter("InputObject", InputObject.Get(context)); } if (PassThru.Expression != null) { targetCommand.AddParameter("PassThru", PassThru.Get(context)); } if (ServiceDisplayName.Expression != null) { targetCommand.AddParameter("DisplayName", ServiceDisplayName.Get(context)); } if (Include.Expression != null) { targetCommand.AddParameter("Include", Include.Get(context)); } if (Exclude.Expression != null) { targetCommand.AddParameter("Exclude", Exclude.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }
// Additional 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 System.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 (Namespace.Expression != null) { targetCommand.AddParameter("Namespace", Namespace.Get(context)); } if (OperationTimeoutSec.Expression != null) { targetCommand.AddParameter("OperationTimeoutSec", OperationTimeoutSec.Get(context)); } if (InputObject.Expression != null) { targetCommand.AddParameter("InputObject", InputObject.Get(context)); } if (Query.Expression != null) { targetCommand.AddParameter("Query", Query.Get(context)); } if (QueryDialect.Expression != null) { targetCommand.AddParameter("QueryDialect", QueryDialect.Get(context)); } if (Property.Expression != null) { targetCommand.AddParameter("Property", Property.Get(context)); } if (PassThru.Expression != null) { targetCommand.AddParameter("PassThru", PassThru.Get(context)); } if (ResourceUri != null) { targetCommand.AddParameter("ResourceUri", ResourceUri.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }
protected override void ProcessRecord() { foreach (String _path in Path) { InvokeProvider.Item.Copy(_path, Destination, Recurse.ToBool(), (Container.ToBool()) ? CopyContainers.CopyTargetContainer : CopyContainers.CopyChildrenOfTargetContainer); if (PassThru.ToBool()) { WriteObject(Path); } } }
// 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 (Job.Expression != null) { targetCommand.AddParameter("Job", Job.Get(context)); } if (PassThru.Expression != null) { targetCommand.AddParameter("PassThru", PassThru.Get(context)); } if (Name.Expression != null) { targetCommand.AddParameter("Name", Name.Get(context)); } if (InstanceId.Expression != null) { targetCommand.AddParameter("InstanceId", InstanceId.Get(context)); } if (JobId.Expression != null) { targetCommand.AddParameter("Id", JobId.Get(context)); } if (State.Expression != null) { targetCommand.AddParameter("State", State.Get(context)); } if (Filter.Expression != null) { targetCommand.AddParameter("Filter", Filter.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }
protected override void ProcessRecord() { object obj = null; if (ParameterSetName == "Stack") { obj = SessionState.Path.SetDefaultLocationStack(StackName); } else { obj = SessionState.Path.SetLocation(Path, ProviderRuntime); } if (PassThru.ToBool()) { WriteObject(obj); } }
protected override void ProcessRecord() { if (Name != null) { foreach (String _name in Name) { foreach (Process _proc in Process.GetProcessesByName(_name)) { if (PassThru.ToBool()) { WriteObject(_proc); } if (Close.ToBool()) { _proc.CloseMainWindow(); } else { _proc.Kill(); } } } } else if (Id != null) { foreach (int _id in Id) { if (PassThru.ToBool()) { WriteObject(Process.GetProcessById(_id)); } if (Close.ToBool()) { Process.GetProcessById(_id).CloseMainWindow(); } else { Process.GetProcessById(_id).Kill(); } } } }
protected override void EndProcessing() { object value = GetVariableValue(); foreach (string name in GetNames()) { try { PSVariable variable = SetVariable(name, value); if (PassThru.ToBool()) { WriteObject(variable); } } catch (SessionStateException ex) { WriteError(ex); } } }
protected override void ProcessRecord() { ServiceController[] _services = ServiceController.GetServices(); foreach (String _name in Name) { foreach (ServiceController _service in _services) { if ((_service.ServiceName == _name) && (_service.CanStop)) { if (!Force.ToBool()) { if (_service.DependentServices.Length != 0) { WriteError(new ErrorRecord(new InvalidOperationException("Cannot stop service \"" + _service.ServiceName + "\" because other services are dependent on it. Use -Force to override."), "ServiceHasDependentServices", ErrorCategory.InvalidOperation, _service)); } else { // Stops the service, waits for the service to be actually stopped before starting it again _service.Stop(); _service.WaitForStatus(ServiceControllerStatus.Stopped); _service.Start(); } } else { _service.Stop(); _service.WaitForStatus(ServiceControllerStatus.Stopped); _service.Start(); } _service.WaitForStatus(ServiceControllerStatus.Running); if (PassThru.ToBool()) { WriteObject(_service); } } } } }
protected override void ProcessRecord() { // TODO: deal with ShouldProcess var variable = new PSVariable(Name, Value, Option); variable.Visibility = Visibility; if (Description != null) { variable.Description = Description; } try { if (!Force && VariableAlreadyExists(variable)) { WriteVariableAlreadyExistsError(variable); return; } SessionState.PSVariable.SetAtScope(variable, Scope, Force); } catch (SessionStateUnauthorizedAccessException ex) { WriteError(ex.ErrorRecord); return; } catch (Exception ex) { WriteError(new ErrorRecord(ex, "", ErrorCategory.InvalidOperation, variable)); return; } if (PassThru.ToBool()) { WriteObject(variable); } }
// 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 System.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 (InputObject.Expression != null) { targetCommand.AddParameter("InputObject", InputObject.Get(context)); } if (MemberType.Expression != null) { targetCommand.AddParameter("MemberType", MemberType.Get(context)); } if (Name.Expression != null) { targetCommand.AddParameter("Name", Name.Get(context)); } if (Value.Expression != null) { targetCommand.AddParameter("Value", Value.Get(context)); } if (SecondValue.Expression != null) { targetCommand.AddParameter("SecondValue", SecondValue.Get(context)); } if (TypeName.Expression != null) { targetCommand.AddParameter("TypeName", TypeName.Get(context)); } if (Force.Expression != null) { targetCommand.AddParameter("Force", Force.Get(context)); } if (PassThru.Expression != null) { targetCommand.AddParameter("PassThru", PassThru.Get(context)); } if (NotePropertyName.Expression != null) { targetCommand.AddParameter("NotePropertyName", NotePropertyName.Get(context)); } if (NotePropertyValue.Expression != null) { targetCommand.AddParameter("NotePropertyValue", NotePropertyValue.Get(context)); } if (NotePropertyMembers.Expression != null) { targetCommand.AddParameter("NotePropertyMembers", NotePropertyMembers.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }
// 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 (LocalCredential.Expression != null) { targetCommand.AddParameter("LocalCredential", LocalCredential.Get(context)); } if (UnjoinDomainCredential.Expression != null) { targetCommand.AddParameter("UnjoinDomainCredential", UnjoinDomainCredential.Get(context)); } if (Credential.Expression != null) { targetCommand.AddParameter("Credential", Credential.Get(context)); } if (DomainName.Expression != null) { targetCommand.AddParameter("DomainName", DomainName.Get(context)); } if (OUPath.Expression != null) { targetCommand.AddParameter("OUPath", OUPath.Get(context)); } if (Server.Expression != null) { targetCommand.AddParameter("Server", Server.Get(context)); } if (Unsecure.Expression != null) { targetCommand.AddParameter("Unsecure", Unsecure.Get(context)); } if (Options.Expression != null) { targetCommand.AddParameter("Options", Options.Get(context)); } if (WorkgroupName.Expression != null) { targetCommand.AddParameter("WorkgroupName", WorkgroupName.Get(context)); } if (Restart.Expression != null) { targetCommand.AddParameter("Restart", Restart.Get(context)); } if (PassThru.Expression != null) { targetCommand.AddParameter("PassThru", PassThru.Get(context)); } if (NewName.Expression != null) { targetCommand.AddParameter("NewName", NewName.Get(context)); } if (Force.Expression != null) { targetCommand.AddParameter("Force", Force.Get(context)); } if (GetIsComputerNameSpecified(context) && (PSRemotingBehavior.Get(context) == RemotingBehavior.Custom)) { targetCommand.AddParameter("ComputerName", PSComputerName.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }
// 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 }); }
// 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 System.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 (CodeDomProvider.Expression != null) { targetCommand.AddParameter("CodeDomProvider", CodeDomProvider.Get(context)); } if (CompilerParameters.Expression != null) { targetCommand.AddParameter("CompilerParameters", CompilerParameters.Get(context)); } if (TypeDefinition.Expression != null) { targetCommand.AddParameter("TypeDefinition", TypeDefinition.Get(context)); } if (Name.Expression != null) { targetCommand.AddParameter("Name", Name.Get(context)); } if (MemberDefinition.Expression != null) { targetCommand.AddParameter("MemberDefinition", MemberDefinition.Get(context)); } if (Namespace.Expression != null) { targetCommand.AddParameter("Namespace", Namespace.Get(context)); } if (UsingNamespace.Expression != null) { targetCommand.AddParameter("UsingNamespace", UsingNamespace.Get(context)); } if (Path.Expression != null) { targetCommand.AddParameter("Path", Path.Get(context)); } if (LiteralPath.Expression != null) { targetCommand.AddParameter("LiteralPath", LiteralPath.Get(context)); } if (AssemblyName.Expression != null) { targetCommand.AddParameter("AssemblyName", AssemblyName.Get(context)); } if (Language.Expression != null) { targetCommand.AddParameter("Language", Language.Get(context)); } if (ReferencedAssemblies.Expression != null) { targetCommand.AddParameter("ReferencedAssemblies", ReferencedAssemblies.Get(context)); } if (OutputAssembly.Expression != null) { targetCommand.AddParameter("OutputAssembly", OutputAssembly.Get(context)); } if (OutputType.Expression != null) { targetCommand.AddParameter("OutputType", OutputType.Get(context)); } if (PassThru.Expression != null) { targetCommand.AddParameter("PassThru", PassThru.Get(context)); } if (IgnoreWarnings.Expression != null) { targetCommand.AddParameter("IgnoreWarnings", IgnoreWarnings.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }
// 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 (Path.Expression != null) { targetCommand.AddParameter("Path", Path.Get(context)); } if (NestedModules.Expression != null) { targetCommand.AddParameter("NestedModules", NestedModules.Get(context)); } if (Guid.Expression != null) { targetCommand.AddParameter("Guid", Guid.Get(context)); } if (Author.Expression != null) { targetCommand.AddParameter("Author", Author.Get(context)); } if (CompanyName.Expression != null) { targetCommand.AddParameter("CompanyName", CompanyName.Get(context)); } if (Copyright.Expression != null) { targetCommand.AddParameter("Copyright", Copyright.Get(context)); } if (RootModule.Expression != null) { targetCommand.AddParameter("RootModule", RootModule.Get(context)); } if (ModuleVersion.Expression != null) { targetCommand.AddParameter("ModuleVersion", ModuleVersion.Get(context)); } if (Description.Expression != null) { targetCommand.AddParameter("Description", Description.Get(context)); } if (ProcessorArchitecture.Expression != null) { targetCommand.AddParameter("ProcessorArchitecture", ProcessorArchitecture.Get(context)); } if (PowerShellVersion.Expression != null) { targetCommand.AddParameter("PowerShellVersion", PowerShellVersion.Get(context)); } if (ClrVersion.Expression != null) { targetCommand.AddParameter("ClrVersion", ClrVersion.Get(context)); } if (DotNetFrameworkVersion.Expression != null) { targetCommand.AddParameter("DotNetFrameworkVersion", DotNetFrameworkVersion.Get(context)); } if (PowerShellHostName.Expression != null) { targetCommand.AddParameter("PowerShellHostName", PowerShellHostName.Get(context)); } if (PowerShellHostVersion.Expression != null) { targetCommand.AddParameter("PowerShellHostVersion", PowerShellHostVersion.Get(context)); } if (RequiredModules.Expression != null) { targetCommand.AddParameter("RequiredModules", RequiredModules.Get(context)); } if (TypesToProcess.Expression != null) { targetCommand.AddParameter("TypesToProcess", TypesToProcess.Get(context)); } if (FormatsToProcess.Expression != null) { targetCommand.AddParameter("FormatsToProcess", FormatsToProcess.Get(context)); } if (ScriptsToProcess.Expression != null) { targetCommand.AddParameter("ScriptsToProcess", ScriptsToProcess.Get(context)); } if (RequiredAssemblies.Expression != null) { targetCommand.AddParameter("RequiredAssemblies", RequiredAssemblies.Get(context)); } if (FileList.Expression != null) { targetCommand.AddParameter("FileList", FileList.Get(context)); } if (ModuleList.Expression != null) { targetCommand.AddParameter("ModuleList", ModuleList.Get(context)); } if (FunctionsToExport.Expression != null) { targetCommand.AddParameter("FunctionsToExport", FunctionsToExport.Get(context)); } if (AliasesToExport.Expression != null) { targetCommand.AddParameter("AliasesToExport", AliasesToExport.Get(context)); } if (VariablesToExport.Expression != null) { targetCommand.AddParameter("VariablesToExport", VariablesToExport.Get(context)); } if (CmdletsToExport.Expression != null) { targetCommand.AddParameter("CmdletsToExport", CmdletsToExport.Get(context)); } if (DscResourcesToExport.Expression != null) { targetCommand.AddParameter("DscResourcesToExport", DscResourcesToExport.Get(context)); } if (PrivateData.Expression != null) { targetCommand.AddParameter("PrivateData", PrivateData.Get(context)); } if (Tags.Expression != null) { targetCommand.AddParameter("Tags", Tags.Get(context)); } if (ProjectUri.Expression != null) { targetCommand.AddParameter("ProjectUri", ProjectUri.Get(context)); } if (LicenseUri.Expression != null) { targetCommand.AddParameter("LicenseUri", LicenseUri.Get(context)); } if (IconUri.Expression != null) { targetCommand.AddParameter("IconUri", IconUri.Get(context)); } if (ReleaseNotes.Expression != null) { targetCommand.AddParameter("ReleaseNotes", ReleaseNotes.Get(context)); } if (HelpInfoUri.Expression != null) { targetCommand.AddParameter("HelpInfoUri", HelpInfoUri.Get(context)); } if (PassThru.Expression != null) { targetCommand.AddParameter("PassThru", PassThru.Get(context)); } if (DefaultCommandPrefix.Expression != null) { targetCommand.AddParameter("DefaultCommandPrefix", DefaultCommandPrefix.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }