How to generate a GUID in PowerShell

 If you ever need a unique id in your script, you can create GUID (globally unique identifier)


In PowerShell 4.0 and earlier you can use [guid] class with its static method.


In PowerShell 5.0 and later, you can use New-Guid cmdlet:


You can use Get-Member to know its object type.

You can also store GUID into a variable like below


If you want to get GUID as string, use ToString method or Guid property.


Both return output of string type, you can verify this using Get-Member.




Comments

Popular Posts

How to Import and Export Delimited Files, like CSV, in PowerShell

PowerShell Arithmetic Operators