Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,16 @@ protected override void ProcessRecord()

case NewPSSessionCommand.UseWindowsPowerShellParameterSet:
{
remoteRunspaces = CreateRunspacesForUseWindowsPowerShellParameterSet();
if (UseWindowsPowerShell)
{
remoteRunspaces = CreateRunspacesForUseWindowsPowerShellParameterSet();
}
else
{
// When -UseWindowsPowerShell:$false is explicitly specified,
// fall back to the default ComputerName parameter set behavior
goto case NewPSSessionCommand.ComputerNameParameterSet;
}
}

break;
Expand Down
45 changes: 45 additions & 0 deletions test/powershell/engine/Remoting/PSSession.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,48 @@ Describe "SkipCACheck and SkipCNCheck PSSession options are required for New-PSS
$er.Exception.ErrorCode | Should -Be $expectedErrorCode
}
}

Describe "New-PSSession -UseWindowsPowerShell switch parameter" -Tag "CI" {

BeforeAll {
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()

if (-not $IsWindows) {
$PSDefaultParameterValues['it:skip'] = $true
}
}

AfterAll {
$global:PSDefaultParameterValues = $originalDefaultParameterValues
}

It "Should respect explicit -UseWindowsPowerShell:`$false parameter value" {
# Test 1: -UseWindowsPowerShell:$true should create a Windows PowerShell 5.1 session
$sessionWithTrue = $null
try {
{ $script:sessionWithTrue = New-PSSession -UseWindowsPowerShell:$true } | Should -Not -Throw
$script:sessionWithTrue | Should -Not -BeNullOrEmpty

# Verify it's Windows PowerShell 5.1
$version = Invoke-Command -Session $script:sessionWithTrue -ScriptBlock { $PSVersionTable.PSVersion }
$version.Major | Should -Be 5
$version.Minor | Should -Be 1
}
finally {
if ($script:sessionWithTrue) { Remove-PSSession $script:sessionWithTrue -ErrorAction SilentlyContinue }
}

# Test 2: -UseWindowsPowerShell:$false should use WSMan transport (not Process)
$sessionWithFalse = $null
try {
{ $script:sessionWithFalse = New-PSSession -UseWindowsPowerShell:$false } | Should -Not -Throw
$script:sessionWithFalse | Should -Not -BeNullOrEmpty

# Transport should be WSMan, not Process
$script:sessionWithFalse.Transport | Should -Be 'WSMan'
}
finally {
if ($script:sessionWithFalse) { Remove-PSSession $script:sessionWithFalse -ErrorAction SilentlyContinue }
}
}
}
Loading