How to Generate GUIDs in PowerShell

Generate GUIDs in PowerShell with [System.Guid]::NewGuid() for random values and with [System.Guid]::CreateVersion7() when the shell runs on .NET 9 or newer.

Recommendation: use [System.Guid]::NewGuid() for random GUIDs and only use GUID v7 when your PowerShell environment runs on a .NET version that supports it.

How to generate GUID v4 in PowerShell

$id = [System.Guid]::NewGuid()
$id

How to generate GUID v7 in PowerShell

$id = [System.Guid]::CreateVersion7()
$id

This requires .NET 9 or newer. In practice that means PowerShell 7.5+ can call the API, while Windows PowerShell 5.1 cannot.

Native support notes

  • PowerShell inherits GUID APIs from .NET.
  • GUID v4 is universally straightforward.
  • GUID v7 is available when PowerShell runs on .NET 9 or newer.

Practical notes

  • Prefer explicit runtime checks in automation scripts if GUID v7 is required.
  • Use GUID v4 when scripts must run across mixed Windows and cross-platform PowerShell environments.
  • See GUID v7 details before depending on sortable GUID semantics.

Frequently Asked Questions

PowerShell typically uses GUID terminology because it relies on .NET's System.Guid type.

[System.Guid]::CreateVersion7() requires .NET 9 or newer. That makes it available in PowerShell 7.5+ and unavailable in Windows PowerShell 5.1.

Learn more

These articles expand on related concepts, formats and practical considerations.

By using this site, you agree to our Privacy Policy and Terms of Service. You are not permitted to use the GUIDs (also known as UUIDs) generated by this site or use any other content, services and information available if you do not agree to these terms.
Disclaimer: All information is provided for general educational and technical reference only. While we aim to keep the content accurate, current and aligned with published standards, no guarantees are made regarding completeness, correctness or suitability for any specific use case.
GUID specifications, best practices, security guidance, database behavior and ecosystem conventions (including cloud platforms and identifier formats) may change over time or differ by implementation. Examples, recommendations and comparisons are illustrative and may not apply universally.
This content should not be considered legal, security, compliance or architectural advice. Before making critical design, security or production decisions, always consult the latest official standards and vendor-specific documentation.
Always evaluate behavior in your own environment.
Standards Compliance: The GUIDs generated by this site conform to RFC 4122 and RFC 9562 specifications whenever possible, using cryptographically secure random number generation.