-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New-Guid -Empty ignores an explicit $false value #25276
Copy link
Copy link
Closed
Labels
Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issuesgeneral cmdlet issuesWG-ReviewedA Working Group has reviewed this and made a recommendationA Working Group has reviewed this and made a recommendation
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
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 @paramsExpected 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.
PowerShell/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewGuidCommand.cs
Line 52 in f194359
| 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.0Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issuesgeneral cmdlet issuesWG-ReviewedA Working Group has reviewed this and made a recommendationA Working Group has reviewed this and made a recommendation
Type
Projects
Status
Reviewed