All You Can Eat GUIDs with PowerShell

With the recent Thanksgiving Holiday, I thought it would be a good time to share a trick that will provide a feast of GUIDS. I like to use this method while doing SharePoint development, but it can really be useful anytime you have a need to create several GUIDs. While it is easy to create a random GUID through the GUID Generator packaged with Visual Studio, or do so through code, I often find myself needing to create many GUIDs at once, so I created this trick to keep a fresh slab of GUIDs at the ready for when the time calls.

This is a PowerShell script that will allow you to create a multitude of GUIDs and save them to a file for later use. It is a quick one-liner, although I have divided it into multiple lines here for readability. I like to simply remove GUIDs from the top as I use them, to ensure I dont duplicate one throughout my development.

@(for($i=0; $i -lt 100; $i++ ) {
  [Guid]::NewGuid().ToString("B") 
}) > "C:\Guids.txt"

When outputting the GUIDs, you may need a specific format. Here is a helpful list: (Source: http://msdn.microsoft.com/en-us/library/97af8hh4.aspx)

Format Output
(Empty) 00000000-0000-0000-0000-000000000000
N 00000000000000000000000000000000
D 00000000-0000-0000-0000-000000000000
B {00000000-0000-0000-0000-000000000000}
P (00000000-0000-0000-0000-000000000000)
X {000000000,00000,00000,{000,000,000,000,000,000,000,000}

I hope this is helpful. Cheers!

Add a Comment

Your email address will not be published. Required fields are marked *