Created
May 5, 2020 09:44
-
-
Save nicolonsky/65922d7d5a11e02fba019b6938e7aaf2 to your computer and use it in GitHub Desktop.
Validates a given input string and checks string is a valid GUID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Test-Guid | |
{ | |
<# | |
.SYNOPSIS | |
Validates a given input string and checks string is a valid GUID | |
.DESCRIPTION | |
Validates a given input string and checks string is a valid GUID by using the .NET method Guid.TryParse | |
.EXAMPLE | |
Test-Guid -InputObject "3363e9e1-00d8-45a1-9c0c-b93ee03f8c13" | |
.NOTES | |
Uses .NET method [guid]::TryParse() | |
#> | |
[Cmdletbinding()] | |
[OutputType([bool])] | |
param | |
( | |
[Parameter(Mandatory = $true, Position = 0, ValueFromPipelineByPropertyName = $true)] | |
[AllowEmptyString()] | |
[string]$InputObject | |
) | |
process{ | |
return [guid]::TryParse($InputObject, $([ref][guid]::Empty)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment