Respect -UseWindowsPowerShell:$false in New-PSSession#26469
Respect -UseWindowsPowerShell:$false in New-PSSession#26469iSazonov merged 4 commits intoPowerShell:masterfrom
Conversation
…alue in New-PSSession
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug where New-PSSession -UseWindowsPowerShell:$false was incorrectly creating a Windows PowerShell 5.1 session instead of a default PowerShell Core session. The issue occurred because the code checked the parameter set name (selected based on parameter presence) rather than the actual boolean value of the switch parameter.
- Fixed parameter value handling in
newrunspacecommand.csby checking the actualUseWindowsPowerShellboolean value - Added test coverage to verify
-UseWindowsPowerShell:$falsecreates the expected default session type
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/System.Management.Automation/engine/remoting/commands/newrunspacecommand.cs | Added conditional check on UseWindowsPowerShell value to properly handle explicit $false, falling back to ComputerName parameter set behavior |
| test/powershell/engine/Remoting/PSSession.Tests.ps1 | Added test to verify -UseWindowsPowerShell:$false produces the same behavior as not specifying the parameter |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@yotsuda The new test failed in CI run: https://github.com/PowerShell/PowerShell/actions/runs/19446455571/job/55648365344?pr=26469#step:3:1406. Please address the failure.
|
- Adopt { ... } | Should -Not -Throw pattern as suggested by @mklement0
- Verify Transport is 'WSMan' (not 'Process') for -UseWindowsPowerShell:$false
- Simpler test that is independent of default PowerShell edition/version
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/System.Management.Automation/engine/remoting/commands/newrunspacecommand.cs
Show resolved
Hide resolved
1. Rename $session1 to $sessionWithTrue for better symmetry with $sessionWithFalse 2. Add null check for $sessionWithFalse to match the pattern used in Test 1 These changes improve test code readability and robustness.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
PR Summary
This PR fixes the issue where
-UseWindowsPowerShell:$falseis not respected inNew-PSSession, causing it to behave the same as-UseWindowsPowerShell:$true.Fixes #26464
Related to #25242
PR Context
When
-UseWindowsPowerShell:$falseis explicitly specified forNew-PSSession, the cmdlet incorrectly creates a Windows PowerShell 5.1 session instead of a default PowerShell Core session. This occurs because the code checks the parameter set name (which is selected based on the presence of the switch, not its value) instead of checking the actual boolean value of theUseWindowsPowerShellparameter.This fix changes the condition to directly check the
UseWindowsPowerShellproperty value, ensuring that explicit$falsevalues are properly respected.Changes
newrunspacecommand.csline 464: Addedif (UseWindowsPowerShell)check in theUseWindowsPowerShellParameterSetcasePSSession.Tests.ps1to verify-UseWindowsPowerShell:$falsecreates a default PowerShell Core sessionTesting
-UseWindowsPowerShell:$falsecreates a session with ShellUri matching the default PowerShell endpointPR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header