GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add GetImportModuleCommand method and session restriction check in ShowCommand by TravisEz13 · Pull Request #25557 · PowerShell/PowerShell

Conversation

@TravisEz13

@TravisEz13 Travis Plunk (TravisEz13) commented May 13, 2025 •
edited by daxian-dbw
Loading

Uh oh!

There was an error while loading. Please reload this page.

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:

  • src/Microsoft.Management.UI.Internal/commandHelpers/ShowCommandHelper.cs: Added the GetImportModuleCommand method to generate a script for importing a module and refreshing command data. This method supports both local and remote runspaces and handles first and subsequent attempts differently.

Improved error handling:

  • src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommand.cs: Added a check in the BeginProcessing method to prevent the ShowCommand feature from running in restricted remoting sessions. If the session is restricted, a terminating error is thrown with an appropriate error message.

PR Context

Fixes #25556
Introduced in #20593

PR Checklist

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Make sure all .h, .cpp, .cs, .ps1 and .psm1 files have the correct copyright header
  • This PR is ready to merge. If this PR is a work in progress, please open this as a Draft Pull Request and mark it as Ready to Review when it is ready to merge.
  • Breaking changes
    • None
    • OR
    • Experimental feature(s) needed
      • Experimental feature name(s):
  • User-facing changes
    • Not Applicable
    • OR
    • Documentation needed
      • Issue filed:
  • Testing - New and feature
    • N/A or can only be tested interactively
    • OR
    • Make sure you've added a new test if existing tests do not effectively test the code changed

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Travis Plunk (TravisEz13) added 3 commits May 13, 2025 11:35
@TravisEz13
Add GetImportModuleCommand method and session restriction check in Sh…
8b92cb5
…owCommand

Fixes issue introduced in PowerShell#20593
@TravisEz13
using braces for clarity
70f7902
@TravisEz13
Add error message for commands not allowed in restricted remoting ses…
6894272
…sions
@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
@microsoft-github-policy-service microsoft-github-policy-service Bot added the Stale label May 31, 2025
@microsoft-github-policy-service microsoft-github-policy-service Bot closed this Jun 11, 2025
@microsoft-github-policy-service microsoft-github-policy-service Bot removed the Stale label Jun 11, 2025
@daxian-dbw Dongbo Wang (daxian-dbw) reopened this Sep 1, 2026
@azure-pipelines

azure-pipelines Bot commented Sep 1, 2026

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@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

azure-pipelines Bot commented Sep 1, 2026

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

daxian-dbw
Dongbo Wang (daxian-dbw) approved these changes Sep 1, 2026
View reviewed changes
@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 started reviewing on behalf of Dongbo Wang (daxian-dbw) September 1, 2026 20:01
View session
Copilot AI reviewed Sep 1, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowCommand/ShowCommand.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/Microsoft.Management.UI.Internal/commandHelpers/ShowCommandHelper.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

iSazonov
Ilya (iSazonov) approved these changes Sep 2, 2026
View reviewed changes
@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit eef0852 into PowerShell:master Sep 2, 2026
38 of 39 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@adityapatwardhan Aditya Patwardhan (adityapatwardhan) added Backport-7.4.x-Approved Backport-7.5.x-Approved Backport-7.6.x-Approved labels Sep 22, 2026
@adityapatwardhan Aditya Patwardhan (adityapatwardhan) mentioned this pull request Sep 22, 2026
[release/v7.4.21] Add GetImportModuleCommand method and session restriction check in ShowCommand #28059
Merged
3 of 9 tasks
@adityapatwardhan Aditya Patwardhan (adityapatwardhan) added Backport-7.4.x-Migrated and removed Backport-7.4.x-Approved labels Sep 22, 2026
@adityapatwardhan Aditya Patwardhan (adityapatwardhan) mentioned this pull request Sep 23, 2026
[release/v7.5.12] Add GetImportModuleCommand method and session restriction check in ShowCommand #28073
Merged
3 of 9 tasks
@adityapatwardhan Aditya Patwardhan (adityapatwardhan) added Backport-7.5.x-Migrated and removed Backport-7.5.x-Approved labels Sep 23, 2026
@adityapatwardhan Aditya Patwardhan (adityapatwardhan) mentioned this pull request Sep 24, 2026
[release/v7.6.7] Add GetImportModuleCommand method and session restriction check in ShowCommand #28088
Merged
3 of 9 tasks
@adityapatwardhan Aditya Patwardhan (adityapatwardhan) added Backport-7.6.x-Migrated and removed Backport-7.6.x-Approved labels Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@daxian-dbw Dongbo Wang (daxian-dbw) daxian-dbw approved these changes
@iSazonov Ilya (iSazonov) iSazonov approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

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

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

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

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@TravisEz13 @daxian-dbw @iSazonov @adityapatwardhan
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.