Generate a list of GUID's

Sometimes you just need a lot of GUID's while programming.  Ofcourse you could use the Visual Studio GUID tool, bu that is a lot of work.

Open a PowerShell console, and paste in the following line to get a list of 100 guid's:

$i=100; while ($i-- -gt 0) { Write-Host ([System.Guid]::NewGuid()) }

4 Comments

  • Or even faster, put this function in your profile:

    #####
    # generates a new Guid
    function NewGuid
    {
    [System.Guid]::NewGuid().ToString()
    }

    All you have to type is:
    [1] ? NewGuid

  • 1..100 | % { Write-Host ([System.Guid]::NewGuid()) }


    ;-)

  • Or, in case you need it to be handy later (and don't care for the function):

    $gg = { [System.Guid]::NewGuid() }
    1..100 | %{ Write-Host (&$gg) }

    Then, later, you can also do:

    $destination = "I want to go to the $(&$gg) Bar & Grill!"

    (Thanks, Leon, for the 1..10 bit. That was new to me!)

  • Awesome! You are a time saver! Thanks

Comments have been disabled for this content.