Home > database >  PowerShell - Writing a new GUID for a board with curly braces
PowerShell - Writing a new GUID for a board with curly braces

Time:03-20

I start with powershell, and I wrote a small and simple code that writes a new GUID to the board.

I used this line:

Set-Clipboard (New-Guid).Guid

It works, but I could not find how to write the GUID with curly brackets.

Surely there are already answers on the subject, but I had a hard time finding.

Maybe give someone an idea?

Thank you!

CodePudding user response:

guid


Alternative implementation / Cryptographic Guid

function New-CryptoGuid {
        $bytes = [System.Security.Cryptography.RandomNumberGenerator]::GetBytes(16)
        return [System.Guid]::new($bytes).ToString("B")
}

$guid = New-CryptoGuid
Write-Host $guid
Set-Clipboard $guid

Output
crypto guid


References

System.Guid
Guid.NewGuid Method - Remarks
System.Guid - Constructor
RandomNumberGenerator.GetBytes Method

  • Related