Skip to content

Change New-Guid to generate UUID v7 by default#27033

Open
SufficientDaikon wants to merge 1 commit intoPowerShell:masterfrom
SufficientDaikon:fix/new-guid-uuid-v7
Open

Change New-Guid to generate UUID v7 by default#27033
SufficientDaikon wants to merge 1 commit intoPowerShell:masterfrom
SufficientDaikon:fix/new-guid-uuid-v7

Conversation

@SufficientDaikon
Copy link

@SufficientDaikon SufficientDaikon commented Mar 15, 2026

PR Summary

Changes New-Guid to generate UUID v7 (RFC 9562) by default using Guid.CreateVersion7(). UUID v7 embeds a millisecond-precision timestamp, making GUIDs monotonically sortable — ideal for database primary keys and distributed systems.

Pester breaking WG

Warning

Breaking change: The default GUID version changes from v4 (fully random) to v7 (timestamp + random). The string format is identical (xxxxxxxx-xxxx-Vxxx-xxxx-xxxxxxxxxxxx), only the version nibble and content differ. Scripts that specifically depend on v4 randomness characteristics should use [Guid]::NewGuid().

The Cmdlets Working Group approved this change without experimental gating.

Users who need UUID v4 can call [Guid]::NewGuid() directly.

Fixes #24895.

What Changed

File Change
NewGuidCommand.cs Guid.NewGuid()Guid.CreateVersion7()
New-Guid.Tests.ps1 Added version-nibble test: position 14 == 7

Before / After

- guid = Empty.ToBool() ? Guid.Empty : Guid.NewGuid();
+ guid = Empty.ToBool() ? Guid.Empty : Guid.CreateVersion7();

Tests

Pester

  • 9/9 Pester tests pass (8 existing + 1 new UUID v7 nibble test)
  • Smoke test: (New-Guid).ToString()[14] returns 7

PR Context

The Cmdlets Working Group approved this change in #24895 — specifically @SteveL-MSFT's decision to change the default with no new switches. Guid.CreateVersion7() has been available since .NET 9; PowerShell targets .NET 11.

A previous attempt (#26256) was opened by Copilot but went stale.


PR Checklist

Replace `Guid.NewGuid()` with `Guid.CreateVersion7()` in the
New-Guid cmdlet. UUID v7 (RFC 9562) embeds a millisecond-precision
timestamp making generated GUIDs monotonically sortable, which is
ideal for database primary keys and distributed systems.

Users who specifically need UUID v4 can call [Guid]::NewGuid() directly.

Fixes PowerShell#24895

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
SufficientDaikon added a commit to SufficientDaikon/PowerShell-Docs that referenced this pull request Mar 25, 2026
Update `New-Guid` reference page for PowerShell 7.6 to reflect the
change from UUID v4 to UUID v7 (`Guid.CreateVersion7()`). Add .NET API
examples per docs team request, and note the breaking change in the
What's New page.

Closes MicrosoftDocs#12884
Related: PowerShell/PowerShell#27033
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add UUID v7 support to New-Guid

1 participant