Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,37 @@ private static string GetSerializedCommandScript()
@"Remove-Item -Path 'function:\PSGetSerializedShowCommandInfo' -Force");
}

/// <summary>
/// Gets the command to be run to in order to import a module and refresh the command data.
/// </summary>
Comment on lines +493 to +494
/// <param name="module">Module we want to import.</param>
/// <param name="isRemoteRunspace">Boolean flag determining whether Show-Command is queried in the local or remote runspace scenario.</param>
/// <param name="isFirstChance">Boolean flag to indicate that it is the second attempt to query Show-Command data.</param>
/// <returns>The command to be run to in order to import a module and refresh the command data.</returns>
internal static string GetImportModuleCommand(string module, bool isRemoteRunspace = false, bool isFirstChance = true)
{
string scriptBase = "Import-Module " + ShowCommandHelper.SingleQuote(module);

if (isRemoteRunspace)
{
if (isFirstChance)
{
scriptBase += ";@(Get-Command " + ShowCommandHelper.CommandTypeSegment + @" -ShowCommandInfo )";
}
else
{
scriptBase += GetSerializedCommandScript();
}
}
else
{
scriptBase += ";@(Get-Command " + ShowCommandHelper.CommandTypeSegment + ")";
}

scriptBase += ShowCommandHelper.GetGetModuleSuffix();
return scriptBase;
}

/// <summary>
/// Gets the command to be run in order to show help for a command.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ public void Dispose()
/// </summary>
protected override void BeginProcessing()
{
if (Utils.IsSessionRestricted(this.Context))
{
Exception e = new InvalidOperationException(HelpErrors.NotAllowedInRestrictedRemoting);
ErrorRecord errorRecord = new ErrorRecord(e, "CommandNotAllowed", ErrorCategory.InvalidOperation, null);
this.ThrowTerminatingError(errorRecord);
}

_showCommandProxy = new ShowCommandProxy(this);

if (_showCommandProxy.ScreenHeight < this.Height)
Expand Down
3 changes: 3 additions & 0 deletions src/System.Management.Automation/resources/HelpErrors.resx
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,7 @@ To update these Help topics, start PowerShell by using the "Run as Administrator
<data name="NoNetworkCommands" xml:space="preserve">
<value>Cannot get help from a network location when in a restricted session.</value>
</data>
<data name="NotAllowedInRestrictedRemoting" xml:space="preserve">
<value>Command not allowed in a restricted session.</value>
</data>
</root>
Loading