mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Get-Help does not work in JEA sessions (#2988)
This commit is contained in:
committed by
Mike Richmond
parent
10f6e2fa6e
commit
1393f45640
@@ -110,14 +110,38 @@ namespace System.Management.Automation
|
||||
// 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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user