-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTest-IsGuid.ps1
44 lines (34 loc) · 1.07 KB
/
Test-IsGuid.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function Test-IsGuid
{
<#
.SYNOPSIS
Cmdlet will check if input string is a valid GUID.
.DESCRIPTION
Cmdlet will check if input string is a valid GUID.
.PARAMETER ObjectGuid
A string representing the GUID to be tested.
.EXAMPLE
PS C:\> Test-IsGuid -ObjectGuid 'value1'
# Output
$False
.EXAMPLE
PS C:\> Test-IsGuid -ObjectGuid '7761bf39-9a9f-42c8-869f-7c6e2689811a'
# Output
$True
.OUTPUTS
System.Boolean
.NOTES
Additional information about the function.
#>
[OutputType([bool])]
param
(
[Parameter(Mandatory = $true)]
[string]
$ObjectGuid
)
# Define verification regex
[regex]$guidRegex = '(?im)^[{(]?[0-9A-F]{8}[-]?(?:[0-9A-F]{4}[-]?){3}[0-9A-F]{12}[)}]?$'
# Check guid against regex
return $ObjectGuid -match $guidRegex
}