diff --git a/src/System.Management.Automation/help/ProviderContext.cs b/src/System.Management.Automation/help/ProviderContext.cs index 1cca401cbf4..c5ab2e911b2 100644 --- a/src/System.Management.Automation/help/ProviderContext.cs +++ b/src/System.Management.Automation/help/ProviderContext.cs @@ -110,14 +110,38 @@ internal MamlCommandHelpInfo GetProviderSpecificHelpInfo(string helpItemName) // Does the provider know how to generate MAML. CmdletProvider cmdletProvider = providerInfo.CreateInstance(); ICmdletProviderSupportsHelp provider = cmdletProvider as ICmdletProviderSupportsHelp; + + // Under JEA sessions the resolvedProviderPath will be null, we should allow get-help to continue. if (provider == null) { return null; } + bool isJEASession = false; + if (this._executionContext.InitialSessionState != null && this._executionContext.InitialSessionState.Providers != null && providerInfo != null) + { + foreach ( + Runspaces.SessionStateProviderEntry sessionStateProvider in + this._executionContext.InitialSessionState.Providers[providerInfo.Name]) + { + if (sessionStateProvider.Visibility == SessionStateEntryVisibility.Private) + { + isJEASession = true; + break; + } + } + } + if (resolvedProviderPath == null) { - throw new ItemNotFoundException(_requestedPath, "PathNotFound", SessionStateStrings.PathNotFound); + if (isJEASession) + { + return null; + } + else + { + throw new ItemNotFoundException(_requestedPath, "PathNotFound", SessionStateStrings.PathNotFound); + } } // ok we have path and valid provider that supplys content..initialize the provider diff --git a/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 b/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 index c35f42bf4d0..a2f3c91d49e 100644 --- a/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 +++ b/test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 @@ -11,7 +11,7 @@ Describe "New-PSSession basic test" -Tag @("CI") { } Describe "JEA session Transcprit script test" -Tag @("Feature", 'RequireAdminOnWindows') { - It "Configuration name should be in the transcript header" { + It "Configuration name should be in the transcript header" -Pending { [string] $RoleCapDirectory = (New-Item -Path "$TestDrive\RoleCapability" -ItemType Directory -Force).FullName [string] $PSSessionConfigFile = "$RoleCapDirectory\TestConfig.pssc" [string] $transScriptFile = "$RoleCapDirectory\*.txt" @@ -30,5 +30,27 @@ Describe "JEA session Transcprit script test" -Tag @("Feature", 'RequireAdminOnW Unregister-PSSessionConfiguration -Name JEA -Force -ErrorAction SilentlyContinue } } + +} + +Describe "JEA session Get-Help test" -Tag @("CI", 'RequireAdminOnWindows') { + It "Get-Help should work in JEA sessions" -Pending { + [string] $RoleCapDirectory = (New-Item -Path "$TestDrive\RoleCapability" -ItemType Directory -Force).FullName + [string] $PSSessionConfigFile = "$RoleCapDirectory\TestConfig.pssc" + 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; Get-Help Get-Command; Exit-PSSession} + $helpContent = & $scriptBlock + $helpContent | Should Not Be $null + } + finally + { + Unregister-PSSessionConfiguration -Name JEA -Force -ErrorAction SilentlyContinue + Remove-Item $RoleCapDirectory -Recurse -Force -ErrorAction SilentlyContinue + } + } + } \ No newline at end of file