Prerequisites
Steps to reproduce
# The *presence* of the switch selects UseWindowsPowerShellParameterSet.
# Irrespective of the switch *value*, CreateRunspacesForUseWindowsPowerShellParameterSet() is called.
# This subverts reasonable user expectation. UseWindowsPowerShell was NOT requested, yet the command
# ignores that request.
New-PSSession -UseWindowsPowerShell:$false
# Likewise, this results in [datetime] output, despite it not being requested.
$params = @{ Since = $false }
Get-Uptime @params
Context:
This is a continuation of the following issues:
Summary:
- The first issue discusses how
Get-Uptime -Since:$false is not respected. That is, despite the explicit $false value, Get-Uptime behaves as if -Since or -Since:$true was specified.
- This behavior was deemed erroneous and the issue was labelled
Up-for-grabs.
- The second issue is a proposal by @mklement0 for a systematic change that would implicitly fix the
Get-Uptime issue and other commands that exhibit the same problem.
- This proposal was rejected due to backwards compatibility concerns.
- I encountered at least 10 commands shipped with PowerShell that exhibit the same problem when looking into the issue further. See here.
- Per @iSazonov in #25015:
Up-for-Grabs - we should fix all cmdlets in the repo if they implement a switch in wrong way.
List of commands to fix:
Request
Fix each command listed above individually, so that explicitly passing a $false value to the specified switch parameter is respected.
Expected behavior
-Switch:$false results in the same behavior as not passing -Switch.
Actual behavior
For the commands listed above, -Switch:$false results in the same behavior as -Switch or -Switch:$true.
Environment data
Name Value
---- -----
PSVersion 7.6.0-preview.3
PSEdition Core
GitCommitId 7.6.0-preview.3
OS Microsoft Windows 10.0.19045
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0, 5.0, 5.1…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Prerequisites
Steps to reproduce
Context:
This is a continuation of the following issues:
Get-Uptime -Sinceignores an explicit$falsevalue #25015-Switch:$falsethe same as omitting a switch when selecting a parameter set #25027Summary:
Get-Uptime -Since:$falseis not respected. That is, despite the explicit$falsevalue,Get-Uptimebehaves as if-Sinceor-Since:$truewas specified.Up-for-grabs.Get-Uptimeissue and other commands that exhibit the same problem.List of commands to fix:
Get-Uptime -SinceGet-Uptime -Sinceignores an explicit$falsevalue #25015New-Guid -EmptyNew-Guid -Emptyignores an explicit$falsevalue #25276Get-Random -Shuffle-Shuffle:$false not respected in Get-Random #26456Get-SecureRandom -ShuffleRespect -Shuffle:$false in Get-SecureRandom #26460Get-TimeZone -ListAvailable-ListAvailable:$false not respected in Get-TimeZone #26462New-PSSession -UseWindowsPowerShell-UseWindowsPowerShell:$false not respected in New-PSSession #26464Split-Path -Qualifier/-NoQualifier/-Leaf/-IsAbsolute(not-Extension/-LeafBase) -Qualifier/-NoQualifier/-Leaf/-IsAbsolute:$false not respected in Split-Path #26470Test-Connection -Repeat/-MtuSize/-Traceroute-Repeat/-MtuSize/-Traceroute:$false not respected in Test-Connection #26475Where-Object(all non-common switch parameters) -[Operator]:$false not respected in Where-Object #26480ConvertTo-Csv -UseCulture:$falseConvertTo-Csv/Export-Csv -UseCulture:$falseuses the wrong delimiter in ouput #26513Export-Csv -UseCulture:$falseConvertTo-Csv/Export-Csv -UseCulture:$falseuses the wrong delimiter in ouput #26513ConvertFrom-Csv -UseCulture:$falseImport-Csv -UseCulture:$falseGet-Culture -ListAvailable:$falseGet-Location -Stack:$falseRequest
Fix each command listed above individually, so that explicitly passing a
$falsevalue to the specified switch parameter is respected.Expected behavior
-Switch:$falseresults in the same behavior as not passing-Switch.Actual behavior
For the commands listed above,
-Switch:$falseresults in the same behavior as-Switchor-Switch:$true.Environment data