Respect -UseWindowsPowerShell:$false in New-PSSession (#26469)

This commit is contained in:
yotsuda
2025-11-21 22:50:32 +05:00
committed by GitHub
parent fb6403d4da
commit e81985d8f2
2 changed files with 55 additions and 1 deletions
@@ -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 }
}
}
}