diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewGuidCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewGuidCommand.cs index 0e466f86d3f..d1d41b312f7 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewGuidCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewGuidCommand.cs @@ -49,7 +49,7 @@ protected override void ProcessRecord() } else { - guid = Empty.ToBool() ? Guid.Empty : Guid.NewGuid(); + guid = Empty.ToBool() ? Guid.Empty : Guid.CreateVersion7(); } WriteObject(guid); diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Guid.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Guid.Tests.ps1 index 8756fed7726..9b082793413 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Guid.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Guid.Tests.ps1 @@ -43,6 +43,12 @@ Describe "New-Guid" -Tags "CI" { $observed | Should -Be $guids } + It "Should generate a UUID v7" { + $guid = New-Guid + # UUID v7 has version nibble '7' at position 14 in the string representation + $guid.ToString()[14] | Should -BeExactly '7' + } + It "Should return different guids with each call" { $guid1 = New-Guid $guid2 = New-Guid