protected override Runspace CreateRunspace(PSHost host) { Runspace runspace = base.CreateRunspace(host); if (!string.IsNullOrEmpty(this.clientVersion)) { SupportedVersionList supportedVersionList = MonadRemoteRunspaceFactory.ExtractSupportedVersionList(runspace); if (supportedVersionList.IsSupported(this.clientVersion)) { runspace.Dispose(); throw new VersionMismatchException(Strings.VersionMismatchDuringCreateRemoteRunspace, supportedVersionList); } } return(runspace); }
public static SupportedVersionList TestConnection(Uri uri, string shell, PSCredential credential, AuthenticationMechanism mechanism, int maxRedirectionCount, bool skipCertificateCheck) { WSManConnectionInfo wsmanConnectionInfo = new WSManConnectionInfo(uri, shell, credential); wsmanConnectionInfo.AuthenticationMechanism = mechanism; wsmanConnectionInfo.MaximumConnectionRedirectionCount = maxRedirectionCount; if (skipCertificateCheck) { wsmanConnectionInfo.SkipCACheck = true; wsmanConnectionInfo.SkipCNCheck = true; wsmanConnectionInfo.SkipRevocationCheck = true; } Runspace runspace = null; SupportedVersionList result = null; Runspace runspace2; runspace = (runspace2 = RunspaceFactory.CreateRunspace(wsmanConnectionInfo)); try { lock (MonadRemoteRunspaceFactory.syncObject) { MonadRemoteRunspaceFactory.runspaceInstances.Add(runspace); } runspace.Open(); result = MonadRemoteRunspaceFactory.ExtractSupportedVersionList(runspace); } finally { if (runspace2 != null) { ((IDisposable)runspace2).Dispose(); } } lock (MonadRemoteRunspaceFactory.syncObject) { MonadRemoteRunspaceFactory.runspaceInstances.Remove(runspace); } return(result); }