-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDelete-User.ps1
71 lines (59 loc) · 2.13 KB
/
Delete-User.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
<#
.SYNOPSIS
Deletes list of users from Workspace ONE UEM (AirWatch)
.DESCRIPTION
.PARAMETER userFile
Path of a CSV file with a list of User Ids. This is required.
.PARAMETER userFileColumn
Column title in CSV file containing User Id values. This is optional, with a default value of "Id".
.INPUTS
AirWatchConfig.json
Serials.csv
.OUTPUTS
NO OUTPUT CURRENTLY:Outputs a CSV log of actions
.NOTES
Version: 1.3
Author: Joshua Clark @MrTechGadget
Creation Date: 07/02/2018
Update Date: 10/13/2022
Site: https://github.com/MrTechGadget/aw-bulkdevices-script
.EXAMPLE
.\Delete-User.ps1 -userFile "User.csv" -userFileColumn "Id.Value"
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=0,ValueFromPipeline=$true,HelpMessage="Path to file listing UserIDs.")]
[string]$userFile,
[Parameter(HelpMessage="Name of Id column in file, default is Id")]
[string]$userFileColumn = "Id"
)
Import-Module .\PSairwatch.psm1
Write-Log -logstring "$($MyInvocation.Line)"
$batchsize = 50
$userList = Read-File $userFile $userFileColumn
$splitUserList = Split-Array -inArray $userList -size $batchsize
$decision = $Host.UI.PromptForChoice(
"Attention! If you proceed, " + $userList.count + " users will be deleted from AirWatch",
"This will occur in " + [Math]::Ceiling($userList.count/$batchsize) + " batches of $batchsize",
@('&Yes', '&No'), 1)
if ($decision -eq 0) {
foreach ($list in $splitUserList) {
$json = Set-AddTagJSON $list
Write-Progress -Activity "Deleting Users..." -Status "Batch $($splitUserList.IndexOf($list)+1) of $($splitUserList.Count)" -PercentComplete ((($splitUserList.IndexOf($list)+1)/($splitUserList.Count))*100)
try {
$result = Send-Post -endpoint "system/users/delete" -body $json
if (!$result) {
Write-Warning "Error Deleting User(s): "
Write-Host $list
} else {
$result
}
}
catch {
Write-Warning "Error Deleting Users"
Write-Host $list
}
}
} else {
Write-Host "Deletion Cancelled"
}