-
Notifications
You must be signed in to change notification settings - Fork 6
/
Delete-Profile.ps1
74 lines (64 loc) · 2.59 KB
/
Delete-Profile.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
<#
.SYNOPSIS
Deletes Profiles given a list of Profile IDs.
.DESCRIPTION
Deletes Profiles given a list of Profile IDs.
.PARAMETER file
Path of a CSV file with a list of Profile IDs. This is required.
.PARAMETER fileColumn
Column title in CSV file containing ProfileId values. This is optional, with a default value of "ProfileId".
.INPUTS
AirWatchConfig.json
CSV File with headers
.OUTPUTS
NO OUTPUT CURRENTLY:Outputs a CSV log of actions
.NOTES
Version: 1.3
Author: Joshua Clark @MrTechGadget
Creation Date: 01/09/2021
Update Date: 10/13/2022
Site: https://github.com/MrTechGadget/aw-bulkdevices-script
.EXAMPLE
Delete-Profile.ps1 -file .\ProfilesTest.csv -fileColumn "ProfileId"
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,HelpMessage="Path to file listing ProfileId.")]
[string]$file,
[Parameter(HelpMessage="Name of Id column in file, default is ProfileId")]
[string]$fileColumn = "ProfileId"
)
Import-Module .\PSairwatch.psm1
Write-Log -logstring "$($MyInvocation.Line)"
$Logfile = "$PSScriptRoot\ProfileDelete.log"
$list = Read-File $file $fileColumn
Write-Log -logstring "$($MyInvocation.Line)" -logfile $Logfile
$decision = $Host.UI.PromptForChoice(
"Attention! If you proceed, " + $list.count + " profiles will be deleted from AirWatch",
"",
@('&Yes', '&No'), 1)
if ($decision -eq 0) {
Write-Log -logstring "Deleting $($list.count) profiles from AirWatch" -logfile $Logfile
foreach ($item in $list) {
Write-Progress -Activity "Deleting Profiles..." -Status "Profile $($list.IndexOf($item)+1) of $($list.Count)" -CurrentOperation "$item" -PercentComplete ((($list.IndexOf($list)+1)/($list.Count))*100)
$endpointURL = "mdm/profiles/${item}"
try {
$result = Send-Delete -endpoint $endpointURL -version "application/json;version=1"
if ($result -ne "") {
Write-Warning ("Error Deleting Profile: $item : $result")
Write-Log -logstring ("Error Deleting Profile: $item : $result") -logfile $Logfile
} else {
Write-Host "$item Deleted $result"
Write-Log -logstring "$item Deleted $result" -logfile $Logfile
}
}
catch {
$err2 = $Error[0].ErrorDetails.Message
Write-Warning "Error Sending Profile Delete Command: $item $err2"
Write-Log -logstring "Error Sending Profile Delete Command: $item $err2" -logfile $Logfile
}
}
} else {
Write-Host "Deletion Cancelled"
Write-Log -logstring "Deletion Cancelled" -logfile $Logfile
}