public void Connect(PSCredential credentials, CultureInfo sessionUiCulture)
        {
            this.CheckDisposed();
            Uri    uri      = null;
            string shellUri = "http://schemas.microsoft.com/powershell/Microsoft.Exchange";

            switch (this.connectionType)
            {
            case PowershellConnectionType.WSMan:
                uri      = new Uri(string.Format("{0}{1}/wsman", this.useSSL ? "https://" : "http://", this.targetServer));
                shellUri = "http://schemas.microsoft.com/powershell/Microsoft.PowerShell";
                break;

            case PowershellConnectionType.OnPrem:
                this.useSSL = false;
                uri         = new Uri(string.Format("{0}{1}/powershell?serializationLevel=Full", this.useSSL ? "https://" : "http://", this.targetServer));
                break;

            case PowershellConnectionType.Tenant:
            {
                string uriString = string.Format("{0}{1}/powershell-liveid?serializationLevel=Full", this.useSSL ? "https://" : "http://", this.targetServer);
                uri = new Uri(uriString);
                break;
            }
            }
            WSManConnectionInfo wsmanConnectionInfo = new WSManConnectionInfo(uri, shellUri, credentials);

            if (this.connectionType == PowershellConnectionType.Tenant)
            {
                wsmanConnectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;
            }
            else if (this.connectionType == PowershellConnectionType.OnPrem)
            {
                wsmanConnectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
            }
            PowershellHostUI     hostUI = new PowershellHostUI();
            RemotePowershellHost host   = new RemotePowershellHost(hostUI);

            wsmanConnectionInfo.Culture = sessionUiCulture;
            wsmanConnectionInfo.MaximumConnectionRedirectionCount = 5;
            this.runspace = RunspaceFactory.CreateRunspace(host, wsmanConnectionInfo);
            this.logger.Log(Strings.HybridInfoOpeningRunspace(uri.ToString()));
            this.runspace.Open();
            this.openedRunspace = true;
        }
Exemplo n.º 2
0
 public RemotePowershellHost(PowershellHostUI hostUI)
 {
     this.hostUI = hostUI;
 }