Skip to content

[release/v7.5.10] Fix the dot-sourcing behavior of pwsh -file for advanced-function scripts - #27761

Merged
Justin Chung (jshigetomi) merged 1 commit into
PowerShell:release/v7.5.10from
SeeminglyScience:backport/release/v7.5.10/27727-463ef4374
Aug 5, 2026
Merged

Justin Chung (jshigetomi) merged 1 commit into
PowerShell:release/v7.5.10from
SeeminglyScience:backport/release/v7.5.10/27727-463ef4374

Conversation

@SeeminglyScience

Copy link
Copy Markdown
Contributor

Backport of #27727 to release/v7.5.10

Triggered by Patrick Meinecke (@SeeminglyScience) on behalf of Dongbo Wang (@daxian-dbw)

Original CL Label: CL-Engine

/cc @PowerShell/powershell-maintainers

Impact

REQUIRED: Choose either Tooling Impact or Customer Impact (or both). At least one checkbox must be selected.

Tooling Impact

  • Required tooling change
  • Optional tooling change (include reasoning)

Customer Impact

  • Customer reported
  • Found internally

Fixes inconsistent WDAC behavior where signed advanced-function scripts failed under pwsh -file while signed simple scripts succeeded. Aligns both code paths so non-noexit file execution behaves consistently.

Regression

REQUIRED: Check exactly one box.

  • Yes
  • No

This is not a regression.

Testing

Validated by original PR scenario coverage for WDAC mode and pwsh -file advanced-function behavior; this backport is a direct cherry-pick with no conflict changes.

Risk

REQUIRED: Check exactly one box.

  • High
  • Medium
  • Low

Engine behavior change is narrowly scoped to the language-mode compatibility check path for script invocation and keeps existing -noexit behavior intact.

Copilot AI lite review requested due to automatic review settings August 4, 2026 20:56
@SeeminglyScience Patrick Meinecke (SeeminglyScience) added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label Aug 4, 2026
@azure-pipelines

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

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.

Pull request overview

Backports the upstream engine fix from #27727 to release/v7.5.10 to align pwsh -File dot-sourcing behavior between “simple scripts” and “advanced-function scripts” under WDAC/CLM scenarios.

Changes:

  • Exposes whether the script cmdlet should rethrow ExitException via a new internal PSScriptCmdlet property.
  • Updates the advanced-script execution path (CommandProcessor) to skip ValidateCompatibleLanguageMode for non--NoExit -File execution, matching the simple-script path behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/System.Management.Automation/engine/runtime/CompiledScriptBlock.cs Adds an internal accessor for the script cmdlet’s “rethrow exit” state used to match language-mode validation behavior.
src/System.Management.Automation/engine/CommandProcessor.cs Aligns dotted script language-mode validation logic with the ScriptCommandProcessor behavior for pwsh -File (non--NoExit).

Comment on lines 780 to +783
// If the script has been dotted, throw an error if it's from a different language mode.
if (!this.UseLocalScope)
// Unless it was a script loaded through -File, in which case the danger of dotting other
// language modes (getting internal functions in the user's state) isn't a danger.
if (!this.UseLocalScope && !scriptCmdlet.ShouldRethrowExitException)
@jshigetomi
Justin Chung (jshigetomi) merged commit 6475d29 into PowerShell:release/v7.5.10 Aug 5, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-Engine Indicates that a PR should be marked as an engine change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants