1 | % { SWITCH (0) { DEFAULT { $_ } } }
1
0
Name Value
---- -----
PSVersion 7.0.1
PSEdition Core
GitCommitId 7.0.1
OS Microsoft Windows 10.0.18363
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0鈥
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Workaround:
powershell
1 | % { SWITCH (0) { DEFAULT { $INPUT } } }
I don't think this is an issue, the switch statement sets $PSItem to the value passed into the switch which is 0 in this case.
This behaviour is undocumented. The automatic variable $_ is documented to be set by commands, the SWITCH statement is not a command.
Ah right, the switch statement is documented to set it, but it does look to be inconsistent with the documentation regarding $PSItem/$_
The design is explicitly documented now.
This issue has been marked as external and has not had any activity for 1 day. It has been be closed for housekeeping purposes.
Most helpful comment
Related to https://github.com/MicrosoftDocs/PowerShell-Docs/issues/5096.