Correct handling of explicit -Empty:$false parameter value in New-Guid (#26140)

This commit is contained in:
Jonathan Gilbert
2025-10-06 09:48:42 +05:00
committed by GitHub
parent be0542b193
commit b5279a25a1
2 changed files with 6 additions and 1 deletions
@@ -49,7 +49,7 @@ namespace Microsoft.PowerShell.Commands
}
else
{
guid = ParameterSetName is "Empty" ? Guid.Empty : Guid.NewGuid();
guid = Empty.ToBool() ? Guid.Empty : Guid.NewGuid();
}
WriteObject(guid);
@@ -17,6 +17,11 @@ Describe "New-Guid" -Tags "CI" {
$guid.ToString() | Should -BeExactly "00000000-0000-0000-0000-000000000000"
}
It "Should respect explicit false value for -Empty" {
$guid = New-Guid -Empty:$false
$guid.ToString() | Should -Not -BeExactly "00000000-0000-0000-0000-000000000000"
}
It "Should convert a string to a guid" {
$guid1 = New-Guid
$guid2 = New-Guid -InputObject $guid1.ToString()