diff --git a/src/Microsoft.Management.UI.Internal/commandHelpers/ShowCommandHelper.cs b/src/Microsoft.Management.UI.Internal/commandHelpers/ShowCommandHelper.cs
index 32c68e961..13dfe839b 100644
--- a/src/Microsoft.Management.UI.Internal/commandHelpers/ShowCommandHelper.cs
+++ b/src/Microsoft.Management.UI.Internal/commandHelpers/ShowCommandHelper.cs
@@ -489,6 +489,37 @@ Function PSGetSerializedShowCommandInfo
@"Remove-Item -Path 'function:\PSGetSerializedShowCommandInfo' -Force");
}
+ ///
+ /// Gets the command to be run to in order to import a module and refresh the command data.
+ ///
+ /// Module we want to import.
+ /// Boolean flag determining whether Show-Command is queried in the local or remote runspace scenario.
+ /// Boolean flag to indicate that it is the second attempt to query Show-Command data.
+ /// The command to be run to in order to import a module and refresh the command data.
+ 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;
+ }
+
///
/// Gets the command to be run in order to show help for a command.
///
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommand.cs
index 60b05807d..01267bab6 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommand.cs
@@ -170,6 +170,13 @@ namespace Microsoft.PowerShell.Commands
///
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)
diff --git a/src/System.Management.Automation/resources/HelpErrors.resx b/src/System.Management.Automation/resources/HelpErrors.resx
index cf8f8fa88..029548fb9 100644
--- a/src/System.Management.Automation/resources/HelpErrors.resx
+++ b/src/System.Management.Automation/resources/HelpErrors.resx
@@ -190,4 +190,7 @@ To update these Help topics, start PowerShell by using the "Run as Administrator
Cannot get help from a network location when in a restricted session.
+
+ Command not allowed in a restricted session.
+