Prerequisites
This is one of many instances of a shipped command that doesn't behave correctly when a switch parameter is explicitly passed a $false value.
For context, see:
Steps to reproduce
New-Guid -Empty:$false
# Equivalent, with hash table splatting:
$params = @{ Empty = $false }
New-Guid @params
Expected behavior
New-Guid emits a non-empty [guid] instance. For example:
Guid
----
d2a83da7-6092-4c06-b8de-3b9aadbd8c94
Actual behavior
The $false value is ignored and an empty [guid] instance is emitted.
Guid
----
00000000-0000-0000-0000-000000000000
New-Guid uses the selected parameter set name (Empty), which is based on the presence of the switch parameter (not its value), to determine the behavior.
|
guid = ParameterSetName is "Empty" ? Guid.Empty : Guid.NewGuid(); |
Behavior should be determined by the value of the Empty property instead.
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
This is one of many instances of a shipped command that doesn't behave correctly when a switch parameter is explicitly passed a
$falsevalue.For context, see:
$falsevalue passed to a switch parameter #25242Steps to reproduce
Expected behavior
New-Guidemits a non-empty[guid]instance. For example:Actual behavior
The
$falsevalue is ignored and an empty[guid]instance is emitted.New-Guiduses the selected parameter set name (Empty), which is based on the presence of the switch parameter (not its value), to determine the behavior.PowerShell/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewGuidCommand.cs
Line 52 in f194359
Behavior should be determined by the value of the
Emptyproperty instead.Environment data