Skip to content

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

Open
SufficientDaikon wants to merge 4 commits into
PowerShell:masterfrom
SufficientDaikon:fix/new-guid-uuid-v7
Open

Change New-Guid to generate UUID v7 by default#27033
SufficientDaikon wants to merge 4 commits into
PowerShell:masterfrom
SufficientDaikon:fix/new-guid-uuid-v7

Conversation

@SufficientDaikon
Copy link
Copy Markdown

@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 <[email protected]>
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
@microsoft-github-policy-service microsoft-github-policy-service Bot added the Review - Needed The PR is being reviewed label Apr 6, 2026
@doctordns
Copy link
Copy Markdown
Collaborator

What is holding this up?

@SufficientDaikon
Copy link
Copy Markdown
Author

What is holding this up?

@doctordns idk, do i need to do anything on my end? is there some sort of the check the code isn't passing?

@kilasuit kilasuit added CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log Review - Maintainer The PR/issue needs a review from the PowerShell repo Maintainers labels Apr 7, 2026
Copilot AI review requested due to automatic review settings May 10, 2026 23:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the New-Guid cmdlet to generate RFC 9562 UUID v7 values by default (time-ordered GUIDs via Guid.CreateVersion7()), aligning the cmdlet’s default behavior with newer UUID guidance while preserving the existing cmdlet surface area.

Changes:

  • Switched New-Guid default generation from Guid.NewGuid() (v4) to Guid.CreateVersion7() (v7) when not using -Empty or -InputObject.
  • Added a Pester assertion to validate the UUID version nibble is 7 in the default string representation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewGuidCommand.cs Changes the cmdlet’s default GUID creation to UUID v7 via Guid.CreateVersion7().
test/powershell/Modules/Microsoft.PowerShell.Utility/New-Guid.Tests.ps1 Adds a test to confirm New-Guid produces UUID v7 by checking the version nibble in the string form.

@SufficientDaikon
Copy link
Copy Markdown
Author

why does copilot keep triggering without being told to? You guys are wasting so much compute with this xD is this why new copilot subs are closed? all the copilot compute is going towards random pull requests xD

anyway, anything needed on my end?

@kilasuit
Copy link
Copy Markdown
Collaborator

@SteveL-MSFT can we get this progressed please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log Review - Maintainer The PR/issue needs a review from the PowerShell repo Maintainers Review - Needed The PR is being reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add UUID v7 support to New-Guid

4 participants