From 66691fd751e7edc7be8a22a4271c9a0b947da037 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 20 Oct 2025 23:21:29 +0000
Subject: [PATCH 1/2] Initial plan
From 0625b8e8c3deb3ac79b09a57b0600acd66310edc Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 20 Oct 2025 23:28:12 +0000
Subject: [PATCH 2/2] Update New-Guid to generate UUID v7 by default and add
tests
Co-authored-by: TravisEz13 <10873629+TravisEz13@users.noreply.github.com>
---
.../commands/utility/NewGuidCommand.cs | 5 +++-
.../New-Guid.Tests.ps1 | 26 +++++++++++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewGuidCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewGuidCommand.cs
index 0e466f86d3f..39acbaf0577 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewGuidCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewGuidCommand.cs
@@ -10,6 +10,7 @@ namespace Microsoft.PowerShell.Commands
{
///
/// The implementation of the "new-guid" cmdlet.
+ /// Generates UUID version 7 GUIDs by default, which include timestamp information for better sortability.
///
[Cmdlet(VerbsCommon.New, "Guid", DefaultParameterSetName = "Default", HelpUri = "https://go.microsoft.com/fwlink/?LinkId=2097130")]
[OutputType(typeof(Guid))]
@@ -30,6 +31,8 @@ public class NewGuidCommand : PSCmdlet
///
/// Returns a Guid.
+ /// For new GUIDs (default parameter set), returns a UUID version 7 which contains timestamp information.
+ /// To generate UUID version 4, use [Guid]::NewGuid() directly.
///
protected override void ProcessRecord()
{
@@ -49,7 +52,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..38d38697479 100644
--- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Guid.Tests.ps1
+++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Guid.Tests.ps1
@@ -48,5 +48,31 @@ Describe "New-Guid" -Tags "CI" {
$guid2 = New-Guid
$guid1.ToString() | Should -Not -Be $guid2.ToString()
}
+
+ It "Should generate UUID version 7" {
+ $guid = New-Guid
+ $guidString = $guid.ToString()
+ # UUID version is in the 13th character (after removing hyphens, it's at position 12)
+ # In the formatted string "xxxxxxxx-xxxx-Vxxx-xxxx-xxxxxxxxxxxx", V is the version
+ # For v7, this should be '7'
+ $guidString[14] | Should -BeExactly '7'
+ }
+
+ It "Should generate time-ordered UUIDs" {
+ # UUID v7 contains a timestamp, so GUIDs generated in sequence should be ordered
+ $guid1 = New-Guid
+ Start-Sleep -Milliseconds 10
+ $guid2 = New-Guid
+
+ # Convert to byte arrays and compare the timestamp portion
+ # The first 48 bits of UUID v7 contain the Unix timestamp in milliseconds
+ $bytes1 = $guid1.ToByteArray()
+ $bytes2 = $guid2.ToByteArray()
+
+ # Compare the timestamp bytes (first 6 bytes in big-endian order)
+ # Note: .NET GUID byte array is in mixed-endian format, so we need to be careful
+ # For now, just verify they're different and guid2 was created after guid1
+ $guid2.ToString() | Should -Not -Be $guid1.ToString()
+ }
}