internal static RunspacePool[] GetRemoteRunspacePools(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable) { WSManConnectionInfo wsmanConnectionInfo = connectionInfo as WSManConnectionInfo; if (wsmanConnectionInfo == null) { throw new NotSupportedException(); } List <RunspacePool> list = new List <RunspacePool>(); foreach (PSObject obj2 in RemoteRunspacePoolEnumeration.GetRemotePools(wsmanConnectionInfo)) { WSManConnectionInfo info2 = wsmanConnectionInfo.Copy(); PSPropertyInfo info3 = obj2.Properties["ShellId"]; PSPropertyInfo info4 = obj2.Properties["State"]; PSPropertyInfo info5 = obj2.Properties["Name"]; PSPropertyInfo info6 = obj2.Properties["ResourceUri"]; if (((info3 != null) && (info4 != null)) && ((info5 != null) && (info6 != null))) { string name = info5.Value.ToString(); string str2 = info6.Value.ToString(); bool isDisconnected = info4.Value.ToString().Equals("Disconnected", StringComparison.OrdinalIgnoreCase); Guid shellId = Guid.Parse(info3.Value.ToString()); if (str2.StartsWith("http://schemas.microsoft.com/powershell/", StringComparison.OrdinalIgnoreCase)) { Collection <PSObject> remoteCommands; UpdateWSManConnectionInfo(info2, obj2); info2.EnableNetworkAccess = true; List <ConnectCommandInfo> list2 = new List <ConnectCommandInfo>(); try { remoteCommands = RemoteRunspacePoolEnumeration.GetRemoteCommands(shellId, info2); } catch (CmdletInvocationException exception) { if ((exception.InnerException == null) || !(exception.InnerException is InvalidOperationException)) { throw; } continue; } foreach (PSObject obj3 in remoteCommands) { PSPropertyInfo info7 = obj3.Properties["CommandId"]; PSPropertyInfo info8 = obj3.Properties["CommandLine"]; if (info7 != null) { string cmdStr = (info8 != null) ? info8.Value.ToString() : string.Empty; Guid cmdId = Guid.Parse(info7.Value.ToString()); list2.Add(new ConnectCommandInfo(cmdId, cmdStr)); } } RunspacePool item = new RunspacePool(isDisconnected, shellId, name, list2.ToArray(), info2, host, typeTable); list.Add(item); } } } return(list.ToArray()); }
private List <RemoteRunspace> CreateRunspacesWhenRunspaceParameterSpecified() { List <RemoteRunspace> list = new List <RemoteRunspace>(); base.ValidateRemoteRunspacesSpecified(); int rsIndex = 0; foreach (PSSession session in this.remoteRunspaceInfos) { if ((session == null) || (session.Runspace == null)) { base.ThrowTerminatingError(new ErrorRecord(new ArgumentNullException("PSSession"), "PSSessionArgumentNull", ErrorCategory.InvalidArgument, null)); } else { try { int num2; RemoteRunspace runspace = (RemoteRunspace)session.Runspace; WSManConnectionInfo connectionInfo = runspace.ConnectionInfo as WSManConnectionInfo; WSManConnectionInfo info2 = null; if (connectionInfo != null) { info2 = connectionInfo.Copy(); info2.EnableNetworkAccess = info2.EnableNetworkAccess || (this.EnableNetworkAccess != false); } else { Uri uri = WSManConnectionInfo.ExtractPropertyAsWsManConnectionInfo <Uri>(runspace.ConnectionInfo, "ConnectionUri", null); string shellUri = WSManConnectionInfo.ExtractPropertyAsWsManConnectionInfo <string>(runspace.ConnectionInfo, "ShellUri", string.Empty); info2 = new WSManConnectionInfo(uri, shellUri, runspace.ConnectionInfo.Credential); base.UpdateConnectionInfo(info2); info2.EnableNetworkAccess = (bool)this.EnableNetworkAccess; } RemoteRunspacePoolInternal remoteRunspacePoolInternal = runspace.RunspacePool.RemoteRunspacePoolInternal; TypeTable typeTable = null; if (((remoteRunspacePoolInternal != null) && (remoteRunspacePoolInternal.DataStructureHandler != null)) && (remoteRunspacePoolInternal.DataStructureHandler.TransportManager != null)) { typeTable = remoteRunspacePoolInternal.DataStructureHandler.TransportManager.Fragmentor.TypeTable; } string runspaceName = this.GetRunspaceName(rsIndex, out num2); RemoteRunspace item = new RemoteRunspace(typeTable, info2, base.Host, this.SessionOption.ApplicationArguments, runspaceName, num2); list.Add(item); } catch (UriFormatException exception) { PipelineWriter objectWriter = this.stream.ObjectWriter; ErrorRecord errorRecord = new ErrorRecord(exception, "CreateRemoteRunspaceFailed", ErrorCategory.InvalidArgument, session); Action <Cmdlet> action = delegate(Cmdlet cmdlet) { cmdlet.WriteError(errorRecord); }; objectWriter.Write(action); } } rsIndex++; } return(list); }