/
Remove-VdcClient.ps1
96 lines (71 loc) · 2.86 KB
/
Remove-VdcClient.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
function Remove-VdcClient {
<#
.SYNOPSIS
Remove registered client agents
.DESCRIPTION
Remove registered client agents.
Provide an array of client IDs to remove a large list at once.
.PARAMETER ClientId
Unique id for one or more clients
.PARAMETER RemoveAssociatedDevice
For a registered Agent, delete the associated Device objects, and only certificates that belong to the associated device.
Delete any related Discovery information. Preserve unrelated device, certificate, and Discovery information in other locations of the Policy tree and Secret Store.
.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
ClientId
.OUTPUTS
None
.EXAMPLE
Remove-VdcClient -ClientId 1234, 5678
Remove clients
.EXAMPLE
Remove-VdcClient -ClientId 1234, 5678 -RemoveAssociatedDevice
Remove clients and associated devices
.LINK
http://VenafiPS.readthedocs.io/en/latest/functions/Remove-VdcClient/
.LINK
https://github.com/Venafi/VenafiPS/blob/main/VenafiPS/Public/Remove-VdcClient.ps1
.LINK
https://docs.venafi.com/Docs/current/TopNav/Content/SDK/WebSDK/r-SDK-POST-ClientDelete.php
#>
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
[Alias('Remove-TppClient')]
param (
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[ValidateNotNullOrEmpty()]
[String[]] $ClientID,
[Parameter()]
[Alias('RemoveAssociatedDevices')]
[switch] $RemoveAssociatedDevice,
[Parameter()]
[psobject] $VenafiSession
)
begin {
Test-VenafiSession -VenafiSession $VenafiSession -Platform 'VDC'
$params = @{
Method = 'Post'
UriLeaf = 'Client/Delete'
Body = @{}
}
}
process {
if ( $PSCmdlet.ShouldProcess('Remove {0} clients' -f $ClientID.Count) ) {
# 5000 clients at a time is an api limitation
for ($i = 0; $i -lt $ClientID.Count; $i += 5000) {
$clientIds = $ClientID[$i..($i + 4999)] | ForEach-Object {
@{ 'ClientId' = $_ }
}
$params.Body.Clients = [array] $clientIds
$params.Body.DeleteAssociatedDevices = $RemoveAssociatedDevice.IsPresent.ToString().ToLower()
$response = Invoke-VenafiRestMethod @params
if ( $response.Errors ) {
Write-Error ($response.Errors | ConvertTo-Json)
}
}
}
}
}