/// <summary> /// Report that a new remote session (runspace) is created. /// </summary> internal static void ReportRemoteSessionCreated( System.Management.Automation.Runspaces.RunspaceConnectionInfo connectionInfo) { RemoteSessionType sessionType = RemoteSessionType.Unknown; RemoteConfigurationType configurationType = RemoteConfigurationType.Unknown; if (connectionInfo is System.Management.Automation.Runspaces.NewProcessConnectionInfo) { sessionType = RemoteSessionType.LocalProcess; configurationType = RemoteConfigurationType.PSDefault; } else { System.Management.Automation.Runspaces.WSManConnectionInfo wsManConnectionInfo = connectionInfo as System.Management.Automation.Runspaces.WSManConnectionInfo; if (wsManConnectionInfo != null) { sessionType = RemoteSessionType.WinRMRemote; // Parse configuration name from ShellUri: // ShellUri = 'http://schemas.microsoft.com/powershell/Microsoft.PowerShell' // ConfigName = 'Microsoft.PowerShell' string configurationName = wsManConnectionInfo.ShellUri; if (!string.IsNullOrEmpty(configurationName)) { int index = configurationName.LastIndexOf('/'); if (index > -1) { configurationName = configurationName.Substring(index + 1); } } configurationType = GetConfigurationTypefromName(configurationName); } else { System.Management.Automation.Runspaces.VMConnectionInfo vmConnectionInfo = connectionInfo as System.Management.Automation.Runspaces.VMConnectionInfo; if (vmConnectionInfo != null) { sessionType = RemoteSessionType.HyperVRemote; configurationType = GetConfigurationTypefromName(vmConnectionInfo.ConfigurationName); } else { System.Management.Automation.Runspaces.ContainerConnectionInfo containerConnectionInfo = connectionInfo as System.Management.Automation.Runspaces.ContainerConnectionInfo; if (containerConnectionInfo != null) { sessionType = RemoteSessionType.ContainerRemote; configurationType = GetConfigurationTypefromName( (containerConnectionInfo.ContainerProc != null) ? containerConnectionInfo.ContainerProc.ConfigurationName : string.Empty); } } } } TelemetryWrapper.TraceMessage("PSNewRemoteSession", new { Type = sessionType, Configuration = configurationType }); }
/// <summary> /// Creates a command transport manager. This will create a new PrioritySendDataCollection which should be used to /// send data to the server. /// </summary> /// <param name="connectionInfo"> /// Connection info to be used for creating the command. /// </param> /// <param name="cmd"> /// Command for which transport manager is created. /// </param> /// <param name="noInput"> /// true if the command has input. /// </param> /// <returns></returns> internal override BaseClientCommandTransportManager CreateClientCommandTransportManager(RunspaceConnectionInfo connectionInfo, ClientRemotePowerShell cmd, bool noInput) { Dbg.Assert(null != cmd, "Cmd cannot be null"); WSManConnectionInfo wsmanConnectionInfo = connectionInfo as WSManConnectionInfo; Dbg.Assert(null != wsmanConnectionInfo, "ConnectionInfo must be WSManConnectionInfo"); WSManClientCommandTransportManager result = new WSManClientCommandTransportManager(wsmanConnectionInfo, _wsManShellOperationHandle, cmd, noInput, this); return result; }
/// <summary> /// Redirect the transport manager to point to a new URI. /// </summary> /// <param name="newUri"> /// Redirect Uri to connect to. /// </param> /// <param name="connectionInfo"> /// Connection info object used for retrieving credential, auth. mechanism etc. /// </param> /// <exception cref="PSInvalidOperationException"> /// 1. Create Session failed with a non-zero error code. /// </exception> internal override void Redirect(Uri newUri, RunspaceConnectionInfo connectionInfo) { CloseSessionAndClearResources(); tracer.WriteLine("Redirecting to URI: {0}", newUri); PSEtwLog.LogAnalyticInformational(PSEventId.URIRedirection, PSOpcode.Connect, PSTask.None, PSKeyword.Transport | PSKeyword.UseAlwaysAnalytic, RunspacePoolInstanceId.ToString(), newUri.ToString()); Initialize(newUri, (WSManConnectionInfo)connectionInfo); //reset startmode _startMode = WSManTransportManagerUtils.tmStartModes.None; CreateAsync(); }