Ejemplo n.º 1
0
        /// <summary>
        /// This constructor will be used to created a remote runspace info
        /// object with a auto generated name.
        /// </summary>
        /// <param name="remoteRunspace">Remote runspace object for which
        /// the info object need to be created</param>
        internal PSSession(RemoteRunspace remoteRunspace)
        {
            _remoteRunspace = remoteRunspace;

            // Use passed in session Id, if available.
            if (remoteRunspace.PSSessionId != -1)
            {
                Id = remoteRunspace.PSSessionId;
            }
            else
            {
                Id = System.Threading.Interlocked.Increment(ref s_seed);
                remoteRunspace.PSSessionId = Id;
            }

            // Use passed in friendly name, if available.
            if (!string.IsNullOrEmpty(remoteRunspace.PSSessionName))
            {
                Name = remoteRunspace.PSSessionName;
            }
            else
            {
                Name = "Runspace" + Id;
                remoteRunspace.PSSessionName = Name;
            }

            switch (remoteRunspace.ConnectionInfo)
            {
            case WSManConnectionInfo _:
                ComputerType = TargetMachineType.RemoteMachine;
                string fullShellName = WSManConnectionInfo.ExtractPropertyAsWsManConnectionInfo <string>(
                    remoteRunspace.ConnectionInfo,
                    "ShellUri", string.Empty);
                ConfigurationName = GetDisplayShellName(fullShellName);
                break;

            case VMConnectionInfo vmConnectionInfo:
                ComputerType      = TargetMachineType.VirtualMachine;
                ConfigurationName = vmConnectionInfo.ConfigurationName;
                break;

            case ContainerConnectionInfo containerConnectionInfo:
                ComputerType      = TargetMachineType.Container;
                ConfigurationName = containerConnectionInfo.ContainerProc.ConfigurationName;
                break;

            case SSHConnectionInfo _:
                ComputerType      = TargetMachineType.RemoteMachine;
                ConfigurationName = "DefaultShell";
                break;

            case NewProcessConnectionInfo _:
                ComputerType = TargetMachineType.RemoteMachine;
                break;

            default:
                Dbg.Assert(false, "Invalid Runspace");
                break;
            }
        }
Ejemplo n.º 2
0
        internal PSSession(RemoteRunspace remoteRunspace)
        {
            this.remoteRunspace = remoteRunspace;
            if (remoteRunspace.Id != -1)
            {
                this.sessionid = remoteRunspace.Id;
            }
            else
            {
                this.sessionid    = Interlocked.Increment(ref seed);
                remoteRunspace.Id = this.sessionid;
            }
            if (!string.IsNullOrEmpty(remoteRunspace.Name))
            {
                this.name = remoteRunspace.Name;
            }
            else
            {
                this.name           = this.AutoGenerateRunspaceName();
                remoteRunspace.Name = this.name;
            }
            string shell = WSManConnectionInfo.ExtractPropertyAsWsManConnectionInfo <string>(remoteRunspace.ConnectionInfo, "ShellUri", string.Empty);

            this.shell = this.GetDisplayShellName(shell);
        }
Ejemplo n.º 3
0
        internal static T ExtractPropertyAsWsManConnectionInfo <T>(RunspaceConnectionInfo rsCI, string property, T defaultValue)
        {
            WSManConnectionInfo info = rsCI as WSManConnectionInfo;

            if (info == null)
            {
                return(defaultValue);
            }
            return((T)typeof(WSManConnectionInfo).GetProperty(property, typeof(T)).GetValue(info, null));
        }
Ejemplo n.º 4
0
        public WSManConnectionInfo Copy()
        {
            var w = new WSManConnectionInfo {
                _connectionUri       = this._connectionUri, _computerName = this._computerName, _scheme = this._scheme, _port = this._port, _appName = this._appName, _shellUri = this._shellUri, _credential = this._credential, UseDefaultWSManPort = this.UseDefaultWSManPort, _authMechanism = this._authMechanism, _maxUriRedirectionCount = this._maxUriRedirectionCount, _maxRecvdDataSizePerCommand = this._maxRecvdDataSizePerCommand, _maxRecvdObjectSize = this._maxRecvdObjectSize, OpenTimeout = base.OpenTimeout, IdleTimeout = base.IdleTimeout, MaxIdleTimeout = base.MaxIdleTimeout, CancelTimeout = base.CancelTimeout,
                OperationTimeout     = base.OperationTimeout, Culture = base.Culture, UICulture = base.UICulture, _thumbPrint = this._thumbPrint, _allowImplicitCredForNegotiate = this._allowImplicitCredForNegotiate, UseCompression = this._useCompression, NoMachineProfile = this._noMachineProfile, _proxyAcessType = this.ProxyAccessType, _proxyAuthentication = this.ProxyAuthentication, _proxyCredential = this.ProxyCredential, _skipCaCheck = this.SkipCACheck, _skipCnCheck = this.SkipCNCheck, _skipRevocationCheck = this.SkipRevocationCheck, _noEncryption = this.NoEncryption, _useUtf16 = this.UseUTF16, _includePortInSPN = this.IncludePortInSPN,
                _enableNetworkAccess = this.EnableNetworkAccess, _outputBufferingMode = this._outputBufferingMode
            };

            w.UseDefaultWSManPort = this.UseDefaultWSManPort;
            return(w);
        }
Ejemplo n.º 5
0
        public static RunspaceConnectionInfo FromPSObjectForRemoting(PSObject obj)
        {
            var connection = new WSManConnectionInfo(PSSessionType.DefaultRemoteShell);

            connection._allowImplicitCredForNegotiate = RemotingDecoder.GetPropertyValue <bool>(obj, "AllowImplicitCredForNegotiate");
            connection._appName       = RemotingDecoder.GetPropertyValue <string>(obj, "ApplicationName");
            connection._authMechanism = RemotingDecoder.GetPropertyValue <WSManNativeApi.WSManAuthenticationMechanism>(obj, "AuthenticationMechanism");
            connection._computerName  = RemotingDecoder.GetPropertyValue <string>(obj, "ComputerName");
            connection._connectionUri = RemotingDecoder.GetPropertyValue <Uri>(obj, "ConnectionUri");
            connection._credential    = RemotingDecoder.GetPropertyValue <PSCredential>(obj, "Credential");
            connection._maxRecvdDataSizePerCommand = RemotingDecoder.GetPropertyValue <int?>(obj, "MaxRecvdDataSizePerCommand");
            connection._enableNetworkAccess        = RemotingDecoder.GetPropertyValue <bool>(obj, "EnableNetworkAccess");
            connection._includePortInSPN           = RemotingDecoder.GetPropertyValue <bool>(obj, "IncludePortInSPN");
            connection._maxRecvdObjectSize         = RemotingDecoder.GetPropertyValue <int?>(obj, "MaxRecvdObjectSize");
            connection._maxUriRedirectionCount     = RemotingDecoder.GetPropertyValue <int>(obj, "MaxUriRedirectionCount");
            connection._noEncryption        = RemotingDecoder.GetPropertyValue <bool>(obj, "NoEncryption");
            connection._noMachineProfile    = RemotingDecoder.GetPropertyValue <bool>(obj, "NoMachineProfile");
            connection._outputBufferingMode = RemotingDecoder.GetPropertyValue <OutputBufferingMode>(obj, "OutputBufferingMode");
            connection._port                = RemotingDecoder.GetPropertyValue <int>(obj, "Port");
            connection._proxyAcessType      = RemotingDecoder.GetPropertyValue <ProxyAccessType>(obj, "ProxyAccessType");
            connection._proxyAuthentication = RemotingDecoder.GetPropertyValue <AuthenticationMechanism>(obj, "ProxyAuthenticationMechanism");
            connection._proxyCredential     = RemotingDecoder.GetPropertyValue <PSCredential>(obj, "ProxyCredential");
            connection._thumbPrint          = RemotingDecoder.GetPropertyValue <string>(obj, "ThumbPrint");
            connection._scheme              = RemotingDecoder.GetPropertyValue <string>(obj, "Scheme");
            connection._shellUri            = RemotingDecoder.GetPropertyValue <string>(obj, "ShellUri");
            connection._skipCaCheck         = RemotingDecoder.GetPropertyValue <bool>(obj, "SkipCaCheck");
            connection._skipCnCheck         = RemotingDecoder.GetPropertyValue <bool>(obj, "SkipCnCheck");
            connection._skipRevocationCheck = RemotingDecoder.GetPropertyValue <bool>(obj, "SkipRevocationCheck");
            connection._useCompression      = RemotingDecoder.GetPropertyValue <bool>(obj, "UseCompression");
            connection._useDefaultWSManPort = RemotingDecoder.GetPropertyValue <bool>(obj, "UseDefaultWSManPort");
            connection._useUtf16            = RemotingDecoder.GetPropertyValue <bool>(obj, "UseUtf16");
            connection.IdleTimeout          = RemotingDecoder.GetPropertyValue <int>(obj, "IdleTimeout");
            connection.MaxIdleTimeout       = RemotingDecoder.GetPropertyValue <int>(obj, "MaxIdleTimeout");
            connection.CancelTimeout        = RemotingDecoder.GetPropertyValue <int>(obj, "CancelTimeout");
            connection.OpenTimeout          = RemotingDecoder.GetPropertyValue <int>(obj, "OpenTimeout");
            connection.OperationTimeout     = RemotingDecoder.GetPropertyValue <int>(obj, "OperationTimeout");
            connection.Culture              = new System.Globalization.CultureInfo(RemotingDecoder.GetPropertyValue <string>(obj, "Culture"));
            connection.UICulture            = new System.Globalization.CultureInfo(RemotingDecoder.GetPropertyValue <string>(obj, "UICulture"));
            return(connection);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// This constructor will be used to created a remote runspace info
        /// object with a auto generated name
        /// </summary>
        /// <param name="remoteRunspace">Remote runspace object for which
        /// the info object need to be created</param>
        internal PSSession(RemoteRunspace remoteRunspace)
        {
            _remoteRunspace = remoteRunspace;

            // Use passed in session Id, if available.
            if (remoteRunspace.PSSessionId != -1)
            {
                Id = remoteRunspace.PSSessionId;
            }
            else
            {
                Id = System.Threading.Interlocked.Increment(ref s_seed);
                remoteRunspace.PSSessionId = Id;
            }

            // Use passed in friendly name, if available.
            if (!string.IsNullOrEmpty(remoteRunspace.PSSessionName))
            {
                Name = remoteRunspace.PSSessionName;
            }
            else
            {
                Name = "Runspace" + Id;
                remoteRunspace.PSSessionName = Name;
            }

            // WSMan session
            if (remoteRunspace.ConnectionInfo is WSManConnectionInfo)
            {
                ComputerType = TargetMachineType.RemoteMachine;

                string fullShellName = WSManConnectionInfo.ExtractPropertyAsWsManConnectionInfo <string>(
                    remoteRunspace.ConnectionInfo,
                    "ShellUri", string.Empty);

                ConfigurationName = GetDisplayShellName(fullShellName);
                return;
            }

            // VM session
            VMConnectionInfo vmConnectionInfo = remoteRunspace.ConnectionInfo as VMConnectionInfo;

            if (vmConnectionInfo != null)
            {
                ComputerType      = TargetMachineType.VirtualMachine;
                ConfigurationName = vmConnectionInfo.ConfigurationName;
                return;
            }

            // Container session
            ContainerConnectionInfo containerConnectionInfo = remoteRunspace.ConnectionInfo as ContainerConnectionInfo;

            if (containerConnectionInfo != null)
            {
                ComputerType      = TargetMachineType.Container;
                ConfigurationName = containerConnectionInfo.ContainerProc.ConfigurationName;
                return;
            }

            // SSH session
            SSHConnectionInfo sshConnectionInfo = remoteRunspace.ConnectionInfo as SSHConnectionInfo;

            if (sshConnectionInfo != null)
            {
                ComputerType      = TargetMachineType.RemoteMachine;
                ConfigurationName = "DefaultShell";
                return;
            }

            // We only support WSMan/VM/Container sessions now.
            Dbg.Assert(false, "Invalid Runspace");
        }