Skip to content

Commit 6421b44

Browse files
Document New-Guid UUID v7 default change
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 #12884 Related: PowerShell/PowerShell#27033
1 parent b9ffc89 commit 6421b44

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

reference/7.6/Microsoft.PowerShell.Utility/New-Guid.md

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Utility
5-
ms.date: 01/24/2024
5+
ms.date: 03/26/2026
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/new-guid?view=powershell-7.6&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
title: New-Guid
@@ -34,8 +34,15 @@ New-Guid [-InputObject <String>] [<CommonParameters>]
3434

3535
## DESCRIPTION
3636

37-
The `New-Guid` cmdlet creates a random globally unique identifier (GUID). If you need a unique ID in
38-
a script, you can create a GUID, as needed.
37+
The `New-Guid` cmdlet creates a Version 7 (time-sortable) globally unique identifier (GUID). If you
38+
need a unique ID in a script, you can create a GUID, as needed. Version 7 UUIDs contain a
39+
millisecond-precision timestamp and are monotonically sortable, making them ideal for database keys
40+
and distributed systems.
41+
42+
> [!NOTE]
43+
> In PowerShell 7.5 and earlier, `New-Guid` created Version 4 (random) UUIDs. Starting in
44+
> PowerShell 7.6, the default changed to Version 7. If you need a Version 4 UUID, use
45+
> `[guid]::NewGuid()` directly.
3946
4047
## EXAMPLES
4148

@@ -46,7 +53,8 @@ New-Guid
4653
```
4754

4855
This command creates a random GUID. Alternatively, you could store the output of this cmdlet in a
49-
variable to use elsewhere in a script.
56+
variable to use elsewhere in a script. Starting in PowerShell 7.6, `New-Guid` generates Version 7
57+
UUIDs by default.
5058

5159
### Example 2: Create an empty GUID
5260

@@ -95,6 +103,18 @@ Guid
95103
01234567-89ab-cdef-0123-456789abcdef
96104
```
97105

106+
### Example 5: Create specific UUID versions using .NET APIs
107+
108+
This example shows how to create specific UUID versions using the underlying .NET APIs directly.
109+
110+
```powershell
111+
# Create a Version 7 UUID (same as New-Guid default in PowerShell 7.6+)
112+
[guid]::CreateVersion7()
113+
114+
# Create a Version 4 UUID (default in PowerShell 7.5 and earlier)
115+
[guid]::NewGuid()
116+
```
117+
98118
## PARAMETERS
99119

100120
### -Empty
@@ -150,8 +170,17 @@ The cmdlet passes string input to the constructor of the **System.Guid** class.
150170
support strings in several formats. For more information, see
151171
[System.Guid(String)](/dotnet/api/system.guid.-ctor#system-guid-ctor(system-string)).
152172
153-
When used without string input or the **Empty** parameter, the cmdlet creates a Version 4
154-
Universally Unique Identifier (UUID). For more information, see
155-
[System.Guid.NewGuid](xref:System.Guid.NewGuid).
173+
When used without string input or the **Empty** parameter, the cmdlet creates a Version 7
174+
Universally Unique Identifier (UUID) as defined in
175+
[RFC 9562](https://www.rfc-editor.org/rfc/rfc9562). Version 7 UUIDs contain a
176+
millisecond-precision timestamp and are monotonically sortable, making them ideal for database keys
177+
and distributed systems.
178+
179+
In previous versions of PowerShell, the cmdlet created a Version 4 (random) UUID. If you need a
180+
Version 4 UUID, use `[guid]::NewGuid()`. To explicitly create a Version 7 UUID, use
181+
`[guid]::CreateVersion7()`.
182+
183+
For more information, see
184+
[System.Guid.CreateVersion7](xref:System.Guid.CreateVersion7).
156185

157186
## RELATED LINKS

reference/docs-conceptual/whats-new/What-s-New-in-PowerShell-76.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ PowerShell 7.6 includes the following updated modules:
3030
- Convert `-ChildPath` parameter to `string[]` for `Join-Path` cmdlet ([#24677][24677]) (Thanks
3131
@ArmaanMcleod!)
3232
- Remove trailing space from event source name ([#24192][24192]) (Thanks @MartinGC94!)
33+
- `New-Guid` now generates Version 7 (time-sortable) UUIDs by default instead of Version 4
34+
(random). The output format is unchanged. Scripts that depend on fully random GUIDs should use
35+
`[guid]::NewGuid()` directly. ([#27033][27033])
3336

3437
## Tab completion improvements
3538

@@ -89,6 +92,8 @@ PowerShell 7.6 includes the following updated modules:
8992

9093
## Cmdlet improvements
9194

95+
- Change `New-Guid` to generate UUID v7 by default using `Guid.CreateVersion7()`
96+
([#27033][27033])
9297
- Add implicit localization fallback to `Import-LocalizedData` ([#19896][19896]) (Thanks
9398
@chrisdent-de!)
9499
- Add `-Delimiter` parameter to `Get-Clipboard` ([#26572][26572]) (Thanks @MartinGC94!)
@@ -302,3 +307,4 @@ This release includes the following experimental features:
302307
[26564]: https://github.com/PowerShell/PowerShell/pull/26564
303308
[26571]: https://github.com/PowerShell/PowerShell/pull/26571
304309
[26572]: https://github.com/PowerShell/PowerShell/pull/26572
310+
[27033]: https://github.com/PowerShell/PowerShell/pull/27033

0 commit comments

Comments
 (0)