/
Test-VdcIdentity.ps1
107 lines (79 loc) · 2.95 KB
/
Test-VdcIdentity.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
function Test-VdcIdentity {
<#
.SYNOPSIS
Test if an identity exists
.DESCRIPTION
Provided with a prefixed universal id, find out if an identity exists.
.PARAMETER Identity
The id that represents the user or group.
.PARAMETER ExistOnly
Only return boolean instead of ID and Exists list. Helpful when validating just 1 identity.
.PARAMETER VenafiSession
Authentication for the function.
The value defaults to the script session object $VenafiSession created by New-VenafiSession.
A TLSPDC token can also be provided.
If providing a TLSPDC token, an environment variable named VDC_SERVER must also be set.
.INPUTS
Identity
.OUTPUTS
PSCustomObject will be returned with properties 'ID', a System.String, and 'Exists', a System.Boolean.
.EXAMPLE
'local:78uhjny657890okjhhh', 'AD+mydomain.com:azsxdcfvgbhnjmlk09877654321' | Test-VdcIdentity
Test multiple identities
.EXAMPLE
Test-VdcIdentity -Identity 'AD+mydomain.com:azsxdcfvgbhnjmlk09877654321' -ExistOnly
Retrieve existence for only one identity, returns boolean
.LINK
http://VenafiPS.readthedocs.io/en/latest/functions/Test-VdcIdentity/
.LINK
https://github.com/Venafi/VenafiPS/blob/main/VenafiPS/Public/Test-VdcIdentity.ps1
.LINK
https://docs.venafi.com/Docs/current/TopNav/Content/SDK/WebSDK/r-SDK-POST-Identity-Validate.php
#>
[CmdletBinding()]
[Alias('Test-TppIdentity')]
param (
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[ValidateScript( {
if ( $_ | Test-VdcIdentityFormat ) {
$true
} else {
throw "'$_' is not a valid Prefixed Universal Id format. See https://docs.venafi.com/Docs/current/TopNav/Content/SDK/WebSDK/r-SDK-IdentityInformation.php."
}
})]
[Alias('PrefixedUniversal', 'Contact', 'IdentityId', 'FullName')]
[string[]] $ID,
[Parameter()]
[Switch] $ExistOnly,
[Parameter()]
[psobject] $VenafiSession
)
begin {
Test-VenafiSession -VenafiSession $VenafiSession -Platform 'VDC'
$params = @{
Method = 'Post'
UriLeaf = 'Identity/Validate'
}
}
process {
foreach ( $thisID in $ID ) {
$params.Body = @{
'ID' = @{}
}
if ( Test-VdcIdentityFormat -ID $thisID -Format 'Universal' ) {
$params.Body.ID.PrefixedUniversal = $thisId
} else {
$params.Body.ID.PrefixedName = $thisId
}
$response = Invoke-VenafiRestMethod @params
if ( $ExistOnly ) {
$null -ne $response.Id
} else {
[PSCustomObject] @{
Identity = $thisId
Exists = ($null -ne $response.Id)
}
}
}
}
}