Skip to content

New-Guid -Empty ignores an explicit $false value #25276

@surfingoldelephant

Description

@surfingoldelephant

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issuesWG-ReviewedA Working Group has reviewed this and made a recommendation

    Type

    No type

    Projects

    Status

    Reviewed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions