From ac317459a02dd38989a8d281f47f594b61ce6311 Mon Sep 17 00:00:00 2001 From: chunqingchen Date: Wed, 14 Dec 2016 19:32:36 -0800 Subject: [PATCH 1/2] PowerShell transcripts should include the configuration name in the transcript header --- .../engine/hostifaces/MshHostUserInterface.cs | 7 ++++++- .../engine/remoting/fanin/PSPrincipal.cs | 5 +++++ .../engine/remoting/server/serverremotesession.cs | 4 +++- .../resources/InternalHostUserInterfaceStrings.resx | 9 +++++---- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs b/src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs index 373c4f920da..8249eb33d01 100644 --- a/src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs +++ b/src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs @@ -453,7 +453,11 @@ private void LogTranscriptHeader(System.Management.Automation.Remoting.PSSenderI psVersionInfo.AppendLine(versionKey + ": " + valueString); } } - + string psConfigurationName = string.Empty; + if (senderInfo != null && !string.IsNullOrEmpty(senderInfo.ConfigurationName)) + { + psConfigurationName = senderInfo.ConfigurationName; + } // Transcribe the transcript header string format = InternalHostUserInterfaceStrings.TranscriptPrologue; string line = @@ -463,6 +467,7 @@ private void LogTranscriptHeader(System.Management.Automation.Remoting.PSSenderI DateTime.Now, username, runAsUser, + psConfigurationName, Environment.MachineName, Environment.OSVersion.VersionString, String.Join(" ", Environment.GetCommandLineArgs()), diff --git a/src/System.Management.Automation/engine/remoting/fanin/PSPrincipal.cs b/src/System.Management.Automation/engine/remoting/fanin/PSPrincipal.cs index 986d280d96c..04e76936831 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/PSPrincipal.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/PSPrincipal.cs @@ -162,6 +162,11 @@ public PSPrimitiveDictionary ApplicationArguments internal set { _applicationArguments = value; } } + /// + /// "ConfigurationName" from the sever remote session + /// + public string ConfigurationName { get; internal set; } + #endregion } diff --git a/src/System.Management.Automation/engine/remoting/server/serverremotesession.cs b/src/System.Management.Automation/engine/remoting/server/serverremotesession.cs index da2767aa274..41d7ce78f56 100644 --- a/src/System.Management.Automation/engine/remoting/server/serverremotesession.cs +++ b/src/System.Management.Automation/engine/remoting/server/serverremotesession.cs @@ -206,7 +206,9 @@ internal static ServerRemoteSession CreateServerRemoteSession(PSSenderInfo sende { throw PSTraceSource.NewInvalidOperationException("RemotingErrorIdStrings.NonExistentInitialSessionStateProvider", configurationProviderId); } - + string shellPrefix = System.Management.Automation.Remoting.Client.WSManNativeApi.ResourceURIPrefix; + int index = configurationProviderId.IndexOf(shellPrefix, StringComparison.OrdinalIgnoreCase); + senderInfo.ConfigurationName = (index == 0) ? configurationProviderId.Substring(shellPrefix.Length) : string.Empty; ServerRemoteSession result = new ServerRemoteSession(senderInfo, configurationProviderId, initializationParameters, diff --git a/src/System.Management.Automation/resources/InternalHostUserInterfaceStrings.resx b/src/System.Management.Automation/resources/InternalHostUserInterfaceStrings.resx index b607e77300e..7ee332f2cf6 100644 --- a/src/System.Management.Automation/resources/InternalHostUserInterfaceStrings.resx +++ b/src/System.Management.Automation/resources/InternalHostUserInterfaceStrings.resx @@ -201,10 +201,11 @@ Windows PowerShell transcript start Start time: {0:yyyyMMddHHmmss} Username: {1} RunAs User: {2} -Machine: {3} ({4}) -Host Application: {5} -Process ID: {6} -{7} +Configuration Name: {3} +Machine: {4} ({5}) +Host Application: {6} +Process ID: {7} +{8} ********************** From 7d1ec00782df8ce9a382be09816754567ecd6bb5 Mon Sep 17 00:00:00 2001 From: chunqingchen Date: Thu, 9 Mar 2017 14:27:12 -0800 Subject: [PATCH 2/2] adding test case for PowerShell transcripts should include the configuration name in the transcript header #2890 --- .../Remoting/RemoteSession.Basic.Tests.ps1 | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 b/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 index a0b0df0ac74..c35f42bf4d0 100644 --- a/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 +++ b/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 @@ -8,4 +8,27 @@ Describe "New-PSSession basic test" -Tag @("CI") { $_.FullyQualifiedErrorId | Should Be "InvalidOperation,Microsoft.PowerShell.Commands.NewPSSessionCommand" } } +} + +Describe "JEA session Transcprit script test" -Tag @("Feature", 'RequireAdminOnWindows') { + It "Configuration name should be in the transcript header" { + [string] $RoleCapDirectory = (New-Item -Path "$TestDrive\RoleCapability" -ItemType Directory -Force).FullName + [string] $PSSessionConfigFile = "$RoleCapDirectory\TestConfig.pssc" + [string] $transScriptFile = "$RoleCapDirectory\*.txt" + try + { + New-PSSessionConfigurationFile -Path $PSSessionConfigFile -TranscriptDirectory $RoleCapDirectory -SessionType RestrictedRemoteServer + Register-PSSessionConfiguration -Name JEA -Path $PSSessionConfigFile -Force -ErrorAction SilentlyContinue + $scriptBlock = {Enter-PSSession -ComputerName Localhost -ConfigurationName JEA; Exit-PSSession} + & $scriptBlock + $headerFile = Get-ChildItem $transScriptFile | Sort-Object LastWriteTime | Select-Object -Last 1 + $header = Get-Content $headerFile | Out-String + $header | Should BeLike "Configuration Name: JEA" + } + finally + { + Unregister-PSSessionConfiguration -Name JEA -Force -ErrorAction SilentlyContinue + } + } + } \ No newline at end of file