Change New-Guid to generate UUID v7 by default#27033
Conversation
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]>
015e5c4 to
bb0794b
Compare
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
|
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? |
There was a problem hiding this comment.
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-Guiddefault generation fromGuid.NewGuid()(v4) toGuid.CreateVersion7()(v7) when not using-Emptyor-InputObject. - Added a Pester assertion to validate the UUID version nibble is
7in 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. |
|
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? |
|
@SteveL-MSFT can we get this progressed please |
PR Summary
Changes
New-Guidto generate UUID v7 (RFC 9562) by default usingGuid.CreateVersion7(). UUID v7 embeds a millisecond-precision timestamp, making GUIDs monotonically sortable ΓÇö ideal for database primary keys and distributed systems.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
NewGuidCommand.csGuid.NewGuid()→Guid.CreateVersion7()New-Guid.Tests.ps17Before / After
Tests
(New-Guid).ToString()[14]returns7PR 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
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header