Tag Archives: powershell

Creating GUIDs in PowerShell

When you work with SharePoint, you end up working a lot with both GUIDs and with PowerShell. Strangely enough, the two together don’t seem to be needed very much but eventually their paths cross. GUIDs in PowerShell are amazingly simple to create but the web is chock full of misinformation and insanely complicated suggestions. I’ve even seen some folks recommend passing parameters to New-Object!

So, just for the sake of clarity, here is how to create GUIDs in PowerShell.  It really doesn’t get much simpler than this!

# Create an empty GUID

   $Id = [GUID]::Empty

# Create a new GUID

   $Id = [GUID]::NewGuid()

# Create a GUID with a value

   $Id = [GUID]("b2e92f11-7f65-41d1-acec-ba051b418bdf")

There’s nothing to it but some people choose to make this so complicated.

Update – 5/31/13 – I discovered a way to make it even simpler!