[Powershell] Generate new UUID

UUID is one of the famous format to unique identify object. When need to write unit test or mock data, we need to pre-generate a set of UUID for testing. This PowerShell script enable us to simplify it.

This script use function NewGUID() to generate random UUID and display in screen. Also, it can use Get-Help command to get details of usage.

<#
.Synopsis
Generate new UUID.
.Description
Powershell script to generate new UUID for different purpose.
.Parameter count
Optional parameter to specific number of UUID to be generated. By default it is 1 and maxium 500.
.Inputs
None.
.Outputs
List of random generated UUID.
.Example
PS> random-uuid.ps1
4ffebeb7-f3b0-493f-bb4d-de7fc4e635e7
.Example
PS> random-uuid.ps1 -count 3
4ffebeb7-f3b0-493f-bb4d-de7fc4e635e7
07f6d85b-25bb-4d93-9820-747cd62c7c57
85bdd2b3-632d-42d5-b398-14cf2f5a1a1c
.Notes
If cannot execute ps1 script. please execute command in PowerShell below with local administrator privilage.
PS> Set-ExecutionPolicy Unrestricted
#>
param(
    # This is the same as .Parameter
    [parameter(Mandatory=$false)]
    [Int]
    [ValidateRange(1,500)] 
    $count = 1
)
for($i = 0; $i -lt $count; $i++) 
{
    $guid = [guid]::NewGuid().toString()
    Write-Host $guid
}

 

About C.H. Ling 262 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.