Skip to content

Add GetImportModuleCommand method and session restriction check in ShowCommand - #25557

Merged
Dongbo Wang (daxian-dbw) merged 3 commits into
PowerShell:masterfrom
TravisEz13:fix-show-command
Sep 2, 2026
Merged

Dongbo Wang (daxian-dbw) merged 3 commits into
PowerShell:masterfrom
TravisEz13:fix-show-command

Conversation

@TravisEz13

@TravisEz13 Travis Plunk (TravisEz13) commented May 13, 2025 •

Copy link
Copy Markdown
Member

PR Summary

Fix #25556

This pull request introduces two main changes to improve functionality and error handling in the ShowCommand feature. The first change brings back a helper method to generate module import scripts with support for remote and local runspaces.

The second change enhances error handling by restricting the ShowCommand feature in specific remoting scenarios.

New functionality:

Improved error handling:

PR Context

Fixes #25556
Introduced in #20593

PR Checklist

@microsoft-github-policy-service microsoft-github-policy-service Bot added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label May 16, 2025
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@daxian-dbw Dongbo Wang (daxian-dbw) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Sep 1, 2026
@daxian-dbw
Dongbo Wang (daxian-dbw) marked this pull request as ready for review September 1, 2026 20:00
@daxian-dbw
Dongbo Wang (daxian-dbw) requested a review from a team as a code owner September 1, 2026 20:00
Copilot AI lite review requested due to automatic review settings September 1, 2026 20:00
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@daxian-dbw Dongbo Wang (daxian-dbw) removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Sep 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR addresses #25556 by restoring a missing helper used by Show-Command to import modules and refresh command metadata (used by the UI when showing command details), and by preventing Show-Command from running in restricted sessions where it isn’t supported.

Changes:

  • Reintroduces GetImportModuleCommand script generation logic in ShowCommandHelper to support module import + command refresh (including remote-runspace scenarios).
  • Adds a restricted-session guard in ShowCommand BeginProcessing to terminate early with a clear error.
  • Adds a new localized resource string for the restricted-session error message.
File summaries
File Description
src/System.Management.Automation/resources/HelpErrors.resx Adds a new error string used when blocking execution in restricted sessions.
src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommand.cs Blocks Show-Command in restricted sessions via Utils.IsSessionRestricted(...) and throws a terminating error.
src/Microsoft.Management.UI.Internal/commandHelpers/ShowCommandHelper.cs Restores GetImportModuleCommand to generate import/refresh scripts for Show-Command module loading flows.
Review details

Suppressed comments (2)

src/Microsoft.Management.UI.Internal/commandHelpers/ShowCommandHelper.cs:511

  • In the remote runspace fallback path, the serialized command script is concatenated directly after Import-Module ... without a statement separator, producing an invalid PowerShell script (e.g., Import-Module 'X'@( ... )). Add a ; before the serialized script so it runs as a separate statement.
                    scriptBase += GetSerializedCommandScript();

src/Microsoft.Management.UI.Internal/commandHelpers/ShowCommandHelper.cs:498

  • isFirstChance is documented as indicating the second attempt, but the name (and default value) indicate the first attempt. This mismatch can easily lead to incorrect future call sites or changes.
        /// <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>
  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport-7.4.x-Migrated Backport-7.5.x-Migrated Backport-7.6.x-Migrated CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show-Command crashes when clicking "Show Details" on a command

5 participants