Skip to content

Instantly share code, notes, and snippets.

@nicolonsky
Created May 5, 2020 09:44
Show Gist options
  • Save nicolonsky/65922d7d5a11e02fba019b6938e7aaf2 to your computer and use it in GitHub Desktop.
Save nicolonsky/65922d7d5a11e02fba019b6938e7aaf2 to your computer and use it in GitHub Desktop.
Validates a given input string and checks string is a valid GUID
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