Skip to main content

How to Generate GUID in PowerShell

Using New-Guid cmdlet

How to Generate GUID in PowerShell. Run New-Guid to generate a PowerShell UUID instantly. Inside a shell script, a bash uuid example validates the 8-4-4-4-12 shape without spawning an external process.

Generate GUID in PowerShell

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

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.

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. Where the language has no built-in type, a c++ uuid reference helps when a 128-bit value needs formatting for output.

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 entropy, random values come from the getrandom crate and map to a 128-bit type, as the rust uuid walkthrough for Cargo projects demonstrates.

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

About the author

Vinitha Pu

Founder and designer

Vinitha Pu is a graphic designer based in Palakkad, Kerala, who builds free, privacy-friendly browser tools. She studied Textile and Apparel Design at Avinashilingam University and completed a C-Tech in Graphic Design at Image Creative Education in 2025. She designs, builds and maintains the UUID generators, validator, decoder and the language and database UUID guides on UUID Generator.

  • Content author: Vinitha Pu
  • Fact checked by: Vinitha Pu. Every generator is checked against the RFC 4122 and RFC 9562 layouts and every code example is run before it goes live.
  • Published Updated

Vinitha Pu on Behance · Vinitha Pu on LinkedIn

Comments & Feedback

Share your experience or ask questions about this tool

Copied!