-
Notifications
You must be signed in to change notification settings - Fork 6
/
Delete-Device.ps1
76 lines (64 loc) · 2.62 KB
/
Delete-Device.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
<#
.SYNOPSIS
Deletes device record from Workspace ONE UEM for a list of SerialNumbers
.DESCRIPTION
.PARAMETER file
Path of a CSV file with a list of Serial Numbers. This is required.
.PARAMETER fileColumn
Column title in CSV file containing SerialNumber values. This is optional, with a default value of "SerialNumber".
.INPUTS
AirWatchConfig.json
Serials.csv
.OUTPUTS
NO OUTPUT CURRENTLY:Outputs a CSV log of actions
.NOTES
Version: 1.2
Author: Joshua Clark @MrTechGadget
Creation Date: 10/02/2021
Updated Date: 10/13/2022
Site: https://github.com/MrTechGadget/aw-bulkdevices-script
.EXAMPLE
.\Delete-Device.ps1 -file "Devices.csv" -fileColumn "SerialNumber"
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=0,ValueFromPipeline=$true,HelpMessage="Path to file listing SerialNumbers.")]
[string]$file,
[Parameter(HelpMessage="Name of Id column in file, default is SerialNumber")]
[string]$fileColumn = "SerialNumber"
)
Import-Module .\PSairwatch.psm1
Write-Log -logstring "$($MyInvocation.Line)"
$Logfile = "$PSScriptRoot\DeleteDevice.log"
$list = Read-File $file $fileColumn
Write-Log -logstring "$($MyInvocation.Line)" -logfile $Logfile
$decision = $Host.UI.PromptForChoice(
"Attention! If you proceed, " + $list.count + " device records will be deleted from Workspace ONE UEM",
"",
@('&Yes', '&No'), 1)
if ($decision -eq 0) {
Write-Log -logstring "Wiping $($list.count) devices deleted from Workspace ONE UEM" -logfile $Logfile
$json = ' '
#$DeletedDevices = Remove-DeviceBulk $DeviceJSON
foreach ($item in $list) {
Write-Progress -Activity "Deleting Devices..." -Status "Batch $($list.IndexOf($item)+1) of $($list.Count)" -CurrentOperation "$item" -PercentComplete ((($list.IndexOf($list)+1)/($list.Count))*100)
$endpointURL = "mdm/devices?searchBy=Serialnumber&id=${item}"
try {
$result = Send-Delete -endpoint $endpointURL -body $json -version "application/json;version=1"
if ($result -ne "") {
Write-Warning "Error Deleting Device: $item :$result"
Write-Log -logstring "Error Deleting Device: $item :$result" -logfile $Logfile
} else {
Write-Host "$item Deleted $result"
Write-Log -logstring "$item Deleted $result" -logfile $Logfile
}
}
catch {
Write-Warning "Error Deleting: $item"
Write-Log -logstring "Error Deleting: $item" -logfile $Logfile
}
}
} else {
Write-Host "Delete Cancelled"
Write-Log -logstring "Delete Cancelled" -logfile $Logfile
}