Skip to main content

How to Generate GUID in PowerShell

Using New-Guid cmdlet

PowerShell doesn't need a third-party module to generate a UUID — .NET's built-in [guid] type and the New-Guid cmdlet handle it out of the box. Either one hands you back a random, RFC 4122-compliant identifier in a single line, whether you're scripting in Windows PowerShell 5.1 or PowerShell 7+. Below you'll find copy-paste ready commands for generating a PowerShell UUID, parsing a string back into a [guid] object, and the newer version 7 option .NET 9 introduced. Save your validated UUIDs for reference in an online notepad at Notepadly. The c# uuid page includes .NET 9 UUID patterns with the new Guid.CreateVersion7() time-sortable API.

Generate GUID in PowerShell

New-Guid
550e8400-e29b-41d4-a716-446655440000

How to Generate a UUID in PowerShell

The fastest way to generate a UUID in PowerShell is [guid]::NewGuid(), which calls .NET's System.Guid generator directly and works in every version back to Windows PowerShell 5.1. PowerShell 7+ (and recent Windows PowerShell builds) also ship the friendlier New-Guid cmdlet, which returns the same kind of object with more readable syntax. See the rust uuid page for Cargo.toml setup, type-safe UUID generation, and Diesel ORM integration.

PowerShell
$myGuid = [guid]::NewGuid()
$myGuid
# Output: 550e8400-e29b-41d4-a716-446655440000

$myGuid2 = New-Guid
$myGuid2
# Output: 6ba7b810-9dad-11d1-80b4-00c04fd430c8

Explanation

Convert a String to a UUID in PowerShell

Sometimes a UUID arrives as plain text — from a config file, an API response, or user input — and you need it back as a proper [guid] object. PowerShell gives you three ways to do this, each with a different tradeoff for handling invalid input. For SwiftUI @Observable models with UUID primary keys, the swift uuid guide has complete implementation examples.

PowerShell
$uuidString = "550e8400-e29b-41d4-a716-446655440000"

# Simple cast - throws if the string is invalid
$guid = [guid]$uuidString

# [guid]::Parse() - same behavior, explicit method call
$guid = [guid]::Parse($uuidString)

# [guid]::TryParse() - safe for untrusted input, returns $true/$false
$result = [guid]::Empty
if ([guid]::TryParse($uuidString, [ref]$result)) {
    Write-Host "Valid UUID: $result"
} else {
    Write-Host "Invalid UUID string"
}

Explanation

Other Options for Generating UUIDs in PowerShell

PowerShell's [guid] type is backed by .NET's System.Guid, which only generates version 4 (random) UUIDs natively — until .NET 9. If you're running PowerShell 7.4+ on a .NET 9 runtime, a newer, time-sortable UUID version 7 option is available too.

PowerShell (.NET 9+)
# Requires PowerShell 7.4+ running on .NET 9
$uuidV7 = [guid]::CreateVersion7()
$uuidV7
# Output: 018f4f3a-7b2c-7c11-9a4d-1e2f3a4b5c6d

Explanation

Comments & Feedback

Share your experience or ask questions about this tool

Copied!