Example #1
0
        } // CoreBeginProcessing

        /// <summary>
        /// Create a throttle operation using NewProcessConnectionInfo
        /// ie., Out-Of-Process runspace.
        /// </summary>
        protected override void CreateHelpersForSpecifiedComputerNames()
        {
            // If we're in ConstrainedLanguage mode and the system is in lockdown mode,
            // ensure that they haven't specified a ScriptBlock or InitScript - as
            // we can't protect that boundary
            if ((Context.LanguageMode == PSLanguageMode.ConstrainedLanguage) &&
                (SystemPolicy.GetSystemLockdownPolicy() != SystemEnforcementMode.Enforce) &&
                ((ScriptBlock != null) || (InitializationScript != null)))
            {
                ThrowTerminatingError(
                    new ErrorRecord(
                        new PSNotSupportedException(RemotingErrorIdStrings.CannotStartJobInconsistentLanguageMode),
                            "CannotStartJobInconsistentLanguageMode",
                            ErrorCategory.PermissionDenied,
                            Context.LanguageMode));
            }

            NewProcessConnectionInfo connectionInfo = new NewProcessConnectionInfo(this.Credential);
            connectionInfo.RunAs32 = _shouldRunAs32;
            connectionInfo.InitializationScript = _initScript;
            connectionInfo.AuthenticationMechanism = this.Authentication;
            connectionInfo.PSVersion = this.PSVersion;

            RemoteRunspace remoteRunspace = (RemoteRunspace)RunspaceFactory.CreateRunspace(connectionInfo, this.Host,
                        Utils.GetTypeTableFromExecutionContextTLS());

            remoteRunspace.Events.ReceivedEvents.PSEventReceived += OnRunspacePSEventReceived;

            Pipeline pipeline = CreatePipeline(remoteRunspace);

            IThrottleOperation operation =
                new ExecutionCmdletHelperComputerName(remoteRunspace, pipeline);

            Operations.Add(operation);
        }
Example #2
0
        protected void CreateHelpersForSpecifiedUris()
        {
            RemoteRunspace remoteRunspace = null;

            for (int i = 0; i < this.ConnectionUri.Length; i++)
            {
                try
                {
                    WSManConnectionInfo connectionInfo = new WSManConnectionInfo {
                        ConnectionUri = this.ConnectionUri[i],
                        ShellUri      = this.ConfigurationName
                    };
                    if (this.CertificateThumbprint != null)
                    {
                        connectionInfo.CertificateThumbprint = this.CertificateThumbprint;
                    }
                    else
                    {
                        connectionInfo.Credential = this.Credential;
                    }
                    connectionInfo.AuthenticationMechanism = this.Authentication;
                    base.UpdateConnectionInfo(connectionInfo);
                    connectionInfo.EnableNetworkAccess = (bool)this.EnableNetworkAccess;
                    remoteRunspace = (RemoteRunspace)RunspaceFactory.CreateRunspace(connectionInfo, base.Host, Utils.GetTypeTableFromExecutionContextTLS(), this.SessionOption.ApplicationArguments);
                    remoteRunspace.Events.ReceivedEvents.PSEventReceived += new PSEventReceivedEventHandler(this.OnRunspacePSEventReceived);
                }
                catch (UriFormatException exception)
                {
                    this.WriteErrorCreateRemoteRunspaceFailed(exception, this.ConnectionUri[i]);
                    continue;
                }
                catch (InvalidOperationException exception2)
                {
                    this.WriteErrorCreateRemoteRunspaceFailed(exception2, this.ConnectionUri[i]);
                    continue;
                }
                catch (ArgumentException exception3)
                {
                    this.WriteErrorCreateRemoteRunspaceFailed(exception3, this.ConnectionUri[i]);
                    continue;
                }
                Pipeline           pipeline = this.CreatePipeline(remoteRunspace);
                IThrottleOperation item     = new ExecutionCmdletHelperComputerName(remoteRunspace, pipeline, this.invokeAndDisconnect);
                this.Operations.Add(item);
            }
        }
Example #3
0
 protected override void CreateHelpersForSpecifiedComputerNames()
 {
     if (((base.Context.LanguageMode == PSLanguageMode.ConstrainedLanguage) && (SystemPolicy.GetSystemLockdownPolicy() != SystemEnforcementMode.Enforce)) && ((this.ScriptBlock != null) || (this.InitializationScript != null)))
     {
         base.ThrowTerminatingError(new ErrorRecord(new PSNotSupportedException(RemotingErrorIdStrings.CannotStartJobInconsistentLanguageMode), "CannotStartJobInconsistentLanguageMode", ErrorCategory.PermissionDenied, base.Context.LanguageMode));
     }
     NewProcessConnectionInfo connectionInfo = new NewProcessConnectionInfo(this.Credential) {
         RunAs32 = this.shouldRunAs32,
         InitializationScript = this.initScript,
         AuthenticationMechanism = this.Authentication,
         PSVersion = this.PSVersion
     };
     RemoteRunspace remoteRunspace = (RemoteRunspace) RunspaceFactory.CreateRunspace(connectionInfo, base.Host, Utils.GetTypeTableFromExecutionContextTLS());
     remoteRunspace.Events.ReceivedEvents.PSEventReceived += new PSEventReceivedEventHandler(this.OnRunspacePSEventReceived);
     Pipeline pipeline = base.CreatePipeline(remoteRunspace);
     IThrottleOperation item = new ExecutionCmdletHelperComputerName(remoteRunspace, pipeline, false);
     base.Operations.Add(item);
 }
Example #4
0
        protected virtual void CreateHelpersForSpecifiedComputerNames()
        {
            base.ValidateComputerName(base.ResolvedComputerNames);
            RemoteRunspace remoteRunspace = null;
            string         str            = this.UseSSL.IsPresent ? "https" : "http";

            for (int i = 0; i < base.ResolvedComputerNames.Length; i++)
            {
                try
                {
                    WSManConnectionInfo connectionInfo = new WSManConnectionInfo {
                        Scheme       = str,
                        ComputerName = base.ResolvedComputerNames[i],
                        Port         = this.Port,
                        AppName      = this.ApplicationName,
                        ShellUri     = this.ConfigurationName
                    };
                    if (this.CertificateThumbprint != null)
                    {
                        connectionInfo.CertificateThumbprint = this.CertificateThumbprint;
                    }
                    else
                    {
                        connectionInfo.Credential = this.Credential;
                    }
                    connectionInfo.AuthenticationMechanism = this.Authentication;
                    base.UpdateConnectionInfo(connectionInfo);
                    connectionInfo.EnableNetworkAccess = (bool)this.EnableNetworkAccess;
                    int    id   = PSSession.GenerateRunspaceId();
                    string name = ((this.DisconnectedSessionName != null) && (this.DisconnectedSessionName.Length > i)) ? this.DisconnectedSessionName[i] : PSSession.ComposeRunspaceName(id);
                    remoteRunspace = new RemoteRunspace(Utils.GetTypeTableFromExecutionContextTLS(), connectionInfo, base.Host, this.SessionOption.ApplicationArguments, name, id);
                    remoteRunspace.Events.ReceivedEvents.PSEventReceived += new PSEventReceivedEventHandler(this.OnRunspacePSEventReceived);
                }
                catch (UriFormatException exception)
                {
                    ErrorRecord errorRecord = new ErrorRecord(exception, "CreateRemoteRunspaceFailed", ErrorCategory.InvalidArgument, base.ResolvedComputerNames[i]);
                    base.WriteError(errorRecord);
                    continue;
                }
                Pipeline           pipeline = this.CreatePipeline(remoteRunspace);
                IThrottleOperation item     = new ExecutionCmdletHelperComputerName(remoteRunspace, pipeline, this.invokeAndDisconnect);
                this.Operations.Add(item);
            }
        }
Example #5
0
        protected override void CreateHelpersForSpecifiedComputerNames()
        {
            if (((base.Context.LanguageMode == PSLanguageMode.ConstrainedLanguage) && (SystemPolicy.GetSystemLockdownPolicy() != SystemEnforcementMode.Enforce)) && ((this.ScriptBlock != null) || (this.InitializationScript != null)))
            {
                base.ThrowTerminatingError(new ErrorRecord(new PSNotSupportedException(RemotingErrorIdStrings.CannotStartJobInconsistentLanguageMode), "CannotStartJobInconsistentLanguageMode", ErrorCategory.PermissionDenied, base.Context.LanguageMode));
            }
            NewProcessConnectionInfo connectionInfo = new NewProcessConnectionInfo(this.Credential)
            {
                RunAs32 = this.shouldRunAs32,
                InitializationScript    = this.initScript,
                AuthenticationMechanism = this.Authentication,
                PSVersion = this.PSVersion
            };
            RemoteRunspace remoteRunspace = (RemoteRunspace)RunspaceFactory.CreateRunspace(connectionInfo, base.Host, Utils.GetTypeTableFromExecutionContextTLS());

            remoteRunspace.Events.ReceivedEvents.PSEventReceived += new PSEventReceivedEventHandler(this.OnRunspacePSEventReceived);
            Pipeline           pipeline = base.CreatePipeline(remoteRunspace);
            IThrottleOperation item     = new ExecutionCmdletHelperComputerName(remoteRunspace, pipeline, false);

            base.Operations.Add(item);
        }
Example #6
0
        }// CreateHelpersForSpecifiedVMSession

        /// <summary>
        /// Creates helper objects with the command for the specified
        /// container IDs or names.
        /// </summary>
        protected virtual void CreateHelpersForSpecifiedContainerSession()
        {
            List<string> resolvedNameList = new List<string>();

            Dbg.Assert((ParameterSetName == PSExecutionCmdlet.ContainerIdParameterSet) ||
                       (ParameterSetName == PSExecutionCmdlet.FilePathContainerIdParameterSet),
                       "Expected ParameterSetName == ContainerId or FilePathContainerId");

            foreach (var input in ContainerId)
            {
                //
                // Create helper objects for container ID or name.
                //
                RemoteRunspace remoteRunspace = null;
                ContainerConnectionInfo connectionInfo = null;

                try
                {
                    //
                    // Hyper-V container uses Hype-V socket as transport.
                    // Windows Server container uses named pipe as transport.
                    //
                    connectionInfo = ContainerConnectionInfo.CreateContainerConnectionInfo(input, RunAsAdministrator.IsPresent, this.ConfigurationName);

                    resolvedNameList.Add(connectionInfo.ComputerName);

                    connectionInfo.CreateContainerProcess();

                    remoteRunspace = new RemoteRunspace(Utils.GetTypeTableFromExecutionContextTLS(),
                        connectionInfo, this.Host, null, null, -1);

                    remoteRunspace.Events.ReceivedEvents.PSEventReceived += OnRunspacePSEventReceived;
                }
                catch (InvalidOperationException e)
                {
                    ErrorRecord errorRecord = new ErrorRecord(e,
                        "CreateRemoteRunspaceForContainerFailed",
                        ErrorCategory.InvalidOperation,
                        null);

                    WriteError(errorRecord);
                    continue;
                }
                catch (ArgumentException e)
                {
                    ErrorRecord errorRecord = new ErrorRecord(e,
                        "CreateRemoteRunspaceForContainerFailed",
                        ErrorCategory.InvalidArgument,
                        null);

                    WriteError(errorRecord);
                    continue;
                }
                catch (Exception e)
                {
                    ErrorRecord errorRecord = new ErrorRecord(e,
                        "CreateRemoteRunspaceForContainerFailed",
                        ErrorCategory.InvalidOperation,
                        null);

                    WriteError(errorRecord);
                    continue;
                }

                Pipeline pipeline = CreatePipeline(remoteRunspace);

                IThrottleOperation operation =
                    new ExecutionCmdletHelperComputerName(remoteRunspace, pipeline, false);

                Operations.Add(operation);
            }

            ResolvedComputerNames = resolvedNameList.ToArray();
        }// CreateHelpersForSpecifiedContainerSession
Example #7
0
        } // CreateHelpersForSpecifiedUris

        /// <summary>
        /// Creates helper objects with the command for the specified
        /// VM GUIDs or VM names.
        /// </summary>
        protected virtual void CreateHelpersForSpecifiedVMSession()
        {
            int inputArraySize;
            int index;
            string command;
            bool[] vmIsRunning;
            Collection<PSObject> results;

            if ((ParameterSetName == PSExecutionCmdlet.VMIdParameterSet) ||
                (ParameterSetName == PSExecutionCmdlet.FilePathVMIdParameterSet))
            {
                inputArraySize = this.VMId.Length;
                this.VMName = new string[inputArraySize];
                vmIsRunning = new bool[inputArraySize];

                for (index = 0; index < inputArraySize; index++)
                {
                    vmIsRunning[index] = false;

                    command = "Get-VM -Id $args[0]";

                    try
                    {
                        results = this.InvokeCommand.InvokeScript(
                            command, false, PipelineResultTypes.None, null, this.VMId[index]);
                    }
                    catch (CommandNotFoundException)
                    {
                        ThrowTerminatingError(
                            new ErrorRecord(
                                new ArgumentException(RemotingErrorIdStrings.HyperVModuleNotAvailable),
                                PSRemotingErrorId.HyperVModuleNotAvailable.ToString(),
                                ErrorCategory.NotInstalled,
                                null));

                        return;
                    }

                    if (results.Count != 1)
                    {
                        this.VMName[index] = string.Empty;
                    }
                    else
                    {
                        this.VMName[index] = (string)results[0].Properties["VMName"].Value;

                        if ((VMState)results[0].Properties["State"].Value == VMState.Running)
                        {
                            vmIsRunning[index] = true;
                        }
                    }
                }
            }
            else
            {
                Dbg.Assert((ParameterSetName == PSExecutionCmdlet.VMNameParameterSet) ||
                           (ParameterSetName == PSExecutionCmdlet.FilePathVMNameParameterSet),
                           "Expected ParameterSetName == VMName or FilePathVMName");

                inputArraySize = this.VMName.Length;
                this.VMId = new Guid[inputArraySize];
                vmIsRunning = new bool[inputArraySize];

                for (index = 0; index < inputArraySize; index++)
                {
                    vmIsRunning[index] = false;

                    command = "Get-VM -Name $args";

                    try
                    {
                        results = this.InvokeCommand.InvokeScript(
                            command, false, PipelineResultTypes.None, null, this.VMName[index]);
                    }
                    catch (CommandNotFoundException)
                    {
                        ThrowTerminatingError(
                            new ErrorRecord(
                                new ArgumentException(RemotingErrorIdStrings.HyperVModuleNotAvailable),
                                PSRemotingErrorId.HyperVModuleNotAvailable.ToString(),
                                ErrorCategory.NotInstalled,
                                null));

                        return;
                    }

                    if (results.Count != 1)
                    {
                        this.VMId[index] = Guid.Empty;
                    }
                    else
                    {
                        this.VMId[index] = (Guid)results[0].Properties["VMId"].Value;
                        this.VMName[index] = (string)results[0].Properties["VMName"].Value;

                        if ((VMState)results[0].Properties["State"].Value == VMState.Running)
                        {
                            vmIsRunning[index] = true;
                        }
                    }
                }
            }

            ResolvedComputerNames = this.VMName;

            for (index = 0; index < ResolvedComputerNames.Length; index++)
            {
                if ((this.VMId[index] == Guid.Empty) &&
                    ((ParameterSetName == PSExecutionCmdlet.VMNameParameterSet) ||
                     (ParameterSetName == PSExecutionCmdlet.FilePathVMNameParameterSet)))
                {
                    WriteError(
                        new ErrorRecord(
                            new ArgumentException(GetMessage(RemotingErrorIdStrings.InvalidVMNameNotSingle,
                                                             this.VMName[index])),
                            PSRemotingErrorId.InvalidVMNameNotSingle.ToString(),
                            ErrorCategory.InvalidArgument,
                            null));

                    continue;
                }
                else if ((this.VMName[index] == string.Empty) &&
                         ((ParameterSetName == PSExecutionCmdlet.VMIdParameterSet) ||
                          (ParameterSetName == PSExecutionCmdlet.FilePathVMIdParameterSet)))
                {
                    WriteError(
                        new ErrorRecord(
                            new ArgumentException(GetMessage(RemotingErrorIdStrings.InvalidVMIdNotSingle,
                                                             this.VMId[index].ToString(null))),
                            PSRemotingErrorId.InvalidVMIdNotSingle.ToString(),
                            ErrorCategory.InvalidArgument,
                            null));

                    continue;
                }
                else if (!vmIsRunning[index])
                {
                    WriteError(
                        new ErrorRecord(
                            new ArgumentException(GetMessage(RemotingErrorIdStrings.InvalidVMState,
                                                             this.VMName[index])),
                            PSRemotingErrorId.InvalidVMState.ToString(),
                            ErrorCategory.InvalidArgument,
                            null));

                    continue;
                }

                // create helper objects for VM GUIDs or names
                RemoteRunspace remoteRunspace = null;
                VMConnectionInfo connectionInfo;

                try
                {
                    connectionInfo = new VMConnectionInfo(this.Credential, this.VMId[index], this.VMName[index], this.ConfigurationName);

                    remoteRunspace = new RemoteRunspace(Utils.GetTypeTableFromExecutionContextTLS(),
                        connectionInfo, this.Host, null, null, -1);

                    remoteRunspace.Events.ReceivedEvents.PSEventReceived += OnRunspacePSEventReceived;
                }
                catch (InvalidOperationException e)
                {
                    ErrorRecord errorRecord = new ErrorRecord(e,
                        "CreateRemoteRunspaceForVMFailed",
                        ErrorCategory.InvalidOperation,
                        null);

                    WriteError(errorRecord);
                }
                catch (ArgumentException e)
                {
                    ErrorRecord errorRecord = new ErrorRecord(e,
                        "CreateRemoteRunspaceForVMFailed",
                        ErrorCategory.InvalidArgument,
                        null);

                    WriteError(errorRecord);
                }

                Pipeline pipeline = CreatePipeline(remoteRunspace);

                IThrottleOperation operation =
                    new ExecutionCmdletHelperComputerName(remoteRunspace, pipeline, false);

                Operations.Add(operation);
            }
        }// CreateHelpersForSpecifiedVMSession
Example #8
0
        } // CreateHelpersForSpecifiedRunspaces

        /// <summary>
        /// Creates helper objects with the command for the specified
        /// remote connection uris
        /// </summary>
        protected void CreateHelpersForSpecifiedUris()
        {
            // create helper objects for computer names
            RemoteRunspace remoteRunspace = null;
            for (int i = 0; i < ConnectionUri.Length; i++)
            {
                try
                {
                    WSManConnectionInfo connectionInfo = new WSManConnectionInfo();

                    connectionInfo.ConnectionUri = ConnectionUri[i];
                    connectionInfo.ShellUri = ConfigurationName;

                    if (CertificateThumbprint != null)
                    {
                        connectionInfo.CertificateThumbprint = CertificateThumbprint;
                    }
                    else
                    {
                        connectionInfo.Credential = Credential;
                    }

                    connectionInfo.AuthenticationMechanism = Authentication;

                    UpdateConnectionInfo(connectionInfo);

                    connectionInfo.EnableNetworkAccess = EnableNetworkAccess;

                    remoteRunspace = (RemoteRunspace)RunspaceFactory.CreateRunspace(connectionInfo, this.Host,
                        Utils.GetTypeTableFromExecutionContextTLS(),
                        this.SessionOption.ApplicationArguments);

                    Dbg.Assert(remoteRunspace != null,
                            "RemoteRunspace object created using URI is null");

                    remoteRunspace.Events.ReceivedEvents.PSEventReceived += OnRunspacePSEventReceived;
                }
                catch (UriFormatException e)
                {
                    WriteErrorCreateRemoteRunspaceFailed(e, ConnectionUri[i]);
                    continue;
                }
                catch (InvalidOperationException e)
                {
                    WriteErrorCreateRemoteRunspaceFailed(e, ConnectionUri[i]);
                    continue;
                }
                catch (ArgumentException e)
                {
                    WriteErrorCreateRemoteRunspaceFailed(e, ConnectionUri[i]);
                    continue;
                }

                Pipeline pipeline = CreatePipeline(remoteRunspace);

                IThrottleOperation operation =
                    new ExecutionCmdletHelperComputerName(remoteRunspace, pipeline, InvokeAndDisconnect);

                Operations.Add(operation);
            }
        } // CreateHelpersForSpecifiedUris
Example #9
0
        }// CreateHelpersForSpecifiedComputerNames

        /// <summary>
        /// Creates helper objects for host names for PSRP over SSH
        /// remoting.
        /// </summary>
        protected void CreateHelpersForSpecifiedHostNames()
        {
            var sshConnectionInfo = new SSHConnectionInfo(this.UserName, this.HostName, this.KeyFilePath);
            var typeTable = TypeTable.LoadDefaultTypeFiles();
            var remoteRunspace = RunspaceFactory.CreateRunspace(sshConnectionInfo, this.Host, typeTable) as RemoteRunspace;
            var pipeline = CreatePipeline(remoteRunspace);

            var operation = new ExecutionCmdletHelperComputerName(remoteRunspace, pipeline);
            Operations.Add(operation);
        }
Example #10
0
        /// <summary>
        /// Creates helper objects with the command for the specified
        /// remote computer names
        /// </summary>
        protected virtual void CreateHelpersForSpecifiedComputerNames()
        {
            ValidateComputerName(ResolvedComputerNames);

            // create helper objects for computer names
            RemoteRunspace remoteRunspace = null;
            string scheme = UseSSL.IsPresent ? WSManConnectionInfo.HttpsScheme : WSManConnectionInfo.HttpScheme;

            for (int i = 0; i < ResolvedComputerNames.Length; i++)
            {
                try
                {
                    WSManConnectionInfo connectionInfo = new WSManConnectionInfo();
                    connectionInfo.Scheme = scheme;
                    connectionInfo.ComputerName = ResolvedComputerNames[i];
                    connectionInfo.Port = Port;
                    connectionInfo.AppName = ApplicationName;
                    connectionInfo.ShellUri = ConfigurationName;
                    if (CertificateThumbprint != null)
                    {
                        connectionInfo.CertificateThumbprint = CertificateThumbprint;
                    }
                    else
                    {
                        connectionInfo.Credential = Credential;
                    }
                    connectionInfo.AuthenticationMechanism = Authentication;

                    UpdateConnectionInfo(connectionInfo);

                    connectionInfo.EnableNetworkAccess = EnableNetworkAccess;

                    // Use the provided session name or create one for this remote runspace so that 
                    // it can be easily identified if it becomes disconnected and is queried on the server.
                    int rsId = PSSession.GenerateRunspaceId();
                    string rsName = (DisconnectedSessionName != null && DisconnectedSessionName.Length > i) ?
                        DisconnectedSessionName[i] : PSSession.ComposeRunspaceName(rsId);

                    remoteRunspace = new RemoteRunspace(Utils.GetTypeTableFromExecutionContextTLS(), connectionInfo,
                        this.Host, this.SessionOption.ApplicationArguments, rsName, rsId);

                    remoteRunspace.Events.ReceivedEvents.PSEventReceived += OnRunspacePSEventReceived;
                }
                catch (UriFormatException uriException)
                {
                    ErrorRecord errorRecord = new ErrorRecord(uriException, "CreateRemoteRunspaceFailed",
                            ErrorCategory.InvalidArgument, ResolvedComputerNames[i]);

                    WriteError(errorRecord);

                    continue;
                }

                Pipeline pipeline = CreatePipeline(remoteRunspace);

                IThrottleOperation operation =
                    new ExecutionCmdletHelperComputerName(remoteRunspace, pipeline, InvokeAndDisconnect);

                Operations.Add(operation);
            }
        }// CreateHelpersForSpecifiedComputerNames
Example #11
0
 protected virtual void CreateHelpersForSpecifiedComputerNames()
 {
     base.ValidateComputerName(base.ResolvedComputerNames);
     RemoteRunspace remoteRunspace = null;
     string str = this.UseSSL.IsPresent ? "https" : "http";
     for (int i = 0; i < base.ResolvedComputerNames.Length; i++)
     {
         try
         {
             WSManConnectionInfo connectionInfo = new WSManConnectionInfo {
                 Scheme = str,
                 ComputerName = base.ResolvedComputerNames[i],
                 Port = this.Port,
                 AppName = this.ApplicationName,
                 ShellUri = this.ConfigurationName
             };
             if (this.CertificateThumbprint != null)
             {
                 connectionInfo.CertificateThumbprint = this.CertificateThumbprint;
             }
             else
             {
                 connectionInfo.Credential = this.Credential;
             }
             connectionInfo.AuthenticationMechanism = this.Authentication;
             base.UpdateConnectionInfo(connectionInfo);
             connectionInfo.EnableNetworkAccess = (bool) this.EnableNetworkAccess;
             int id = PSSession.GenerateRunspaceId();
             string name = ((this.DisconnectedSessionName != null) && (this.DisconnectedSessionName.Length > i)) ? this.DisconnectedSessionName[i] : PSSession.ComposeRunspaceName(id);
             remoteRunspace = new RemoteRunspace(Utils.GetTypeTableFromExecutionContextTLS(), connectionInfo, base.Host, this.SessionOption.ApplicationArguments, name, id);
             remoteRunspace.Events.ReceivedEvents.PSEventReceived += new PSEventReceivedEventHandler(this.OnRunspacePSEventReceived);
         }
         catch (UriFormatException exception)
         {
             ErrorRecord errorRecord = new ErrorRecord(exception, "CreateRemoteRunspaceFailed", ErrorCategory.InvalidArgument, base.ResolvedComputerNames[i]);
             base.WriteError(errorRecord);
             continue;
         }
         Pipeline pipeline = this.CreatePipeline(remoteRunspace);
         IThrottleOperation item = new ExecutionCmdletHelperComputerName(remoteRunspace, pipeline, this.invokeAndDisconnect);
         this.Operations.Add(item);
     }
 }
Example #12
0
 protected void CreateHelpersForSpecifiedUris()
 {
     RemoteRunspace remoteRunspace = null;
     for (int i = 0; i < this.ConnectionUri.Length; i++)
     {
         try
         {
             WSManConnectionInfo connectionInfo = new WSManConnectionInfo {
                 ConnectionUri = this.ConnectionUri[i],
                 ShellUri = this.ConfigurationName
             };
             if (this.CertificateThumbprint != null)
             {
                 connectionInfo.CertificateThumbprint = this.CertificateThumbprint;
             }
             else
             {
                 connectionInfo.Credential = this.Credential;
             }
             connectionInfo.AuthenticationMechanism = this.Authentication;
             base.UpdateConnectionInfo(connectionInfo);
             connectionInfo.EnableNetworkAccess = (bool) this.EnableNetworkAccess;
             remoteRunspace = (RemoteRunspace) RunspaceFactory.CreateRunspace(connectionInfo, base.Host, Utils.GetTypeTableFromExecutionContextTLS(), this.SessionOption.ApplicationArguments);
             remoteRunspace.Events.ReceivedEvents.PSEventReceived += new PSEventReceivedEventHandler(this.OnRunspacePSEventReceived);
         }
         catch (UriFormatException exception)
         {
             this.WriteErrorCreateRemoteRunspaceFailed(exception, this.ConnectionUri[i]);
             continue;
         }
         catch (InvalidOperationException exception2)
         {
             this.WriteErrorCreateRemoteRunspaceFailed(exception2, this.ConnectionUri[i]);
             continue;
         }
         catch (ArgumentException exception3)
         {
             this.WriteErrorCreateRemoteRunspaceFailed(exception3, this.ConnectionUri[i]);
             continue;
         }
         Pipeline pipeline = this.CreatePipeline(remoteRunspace);
         IThrottleOperation item = new ExecutionCmdletHelperComputerName(remoteRunspace, pipeline, this.invokeAndDisconnect);
         this.Operations.Add(item);
     }
 }
Example #13
0
        } // CoreBeginProcessing

        /// <summary>
        /// Create a throttle operation using NewProcessConnectionInfo 
        /// ie., Out-Of-Process runspace.
        /// </summary>
        protected override void CreateHelpersForSpecifiedComputerNames()
        {
            // If we're in ConstrainedLanguage mode and the system is in lockdown mode,
            // ensure that they haven't specified a ScriptBlock or InitScript - as
            // we can't protect that boundary
            if ((Context.LanguageMode == PSLanguageMode.ConstrainedLanguage) &&
                (SystemPolicy.GetSystemLockdownPolicy() != SystemEnforcementMode.Enforce) &&
                ((ScriptBlock != null) || (InitializationScript != null)))
            {
                ThrowTerminatingError(
                    new ErrorRecord(
                        new PSNotSupportedException(RemotingErrorIdStrings.CannotStartJobInconsistentLanguageMode),
                            "CannotStartJobInconsistentLanguageMode",
                            ErrorCategory.PermissionDenied,
                            Context.LanguageMode));
            }

            NewProcessConnectionInfo connectionInfo = new NewProcessConnectionInfo(this.Credential);
            connectionInfo.RunAs32 = _shouldRunAs32;
            connectionInfo.InitializationScript = _initScript;
            connectionInfo.AuthenticationMechanism = this.Authentication;
            connectionInfo.PSVersion = this.PSVersion;

            RemoteRunspace remoteRunspace = (RemoteRunspace)RunspaceFactory.CreateRunspace(connectionInfo, this.Host,
                        Utils.GetTypeTableFromExecutionContextTLS());

            remoteRunspace.Events.ReceivedEvents.PSEventReceived += OnRunspacePSEventReceived;

            Pipeline pipeline = CreatePipeline(remoteRunspace);

            IThrottleOperation operation =
                new ExecutionCmdletHelperComputerName(remoteRunspace, pipeline);

            Operations.Add(operation);
        }