Skip to content

Commit

Permalink
Added Delete-Profile script
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTechGadget committed Jan 10, 2021
1 parent a257c82 commit 53277ed
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 7 deletions.
81 changes: 81 additions & 0 deletions Delete-Profile.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<#
.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.0
Author: Joshua Clark @MrTechGadget
Creation Date: 01/09/2021
Update Date: 01/09/2021
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

$Logfile = "$PSScriptRoot\ProfileDelete.log"

Function Write-Log
{
Param ([string]$logstring)

$logstring = ((Get-Date).ToString() + " - " + $logstring)
Add-content $Logfile -value $logstring
}

$list = Read-File $file $fileColumn

Write-Log "$($MyInvocation.Line)"

$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 "Deleting $($list.count) profiles from AirWatch"

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 ("Error Deleting Profile: $item : $result")
} else {
Write-Host "$item Deleted $result"
Write-Log "$item Deleted $result"
}
}
catch {
$err2 = $Error[0].ErrorDetails.Message
Write-Warning "Error Sending Profile Delete Command: $item $err2"
Write-Log "Error Sending Profile Delete Command: $item $err2"
}
}
} else {
Write-Host "Deletion Cancelled"
Write-Log "Deletion Cancelled"
}
4 changes: 2 additions & 2 deletions Get-DeviceDetails.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
Path of a CSV file with a list of Serial Numbers and desired Asset Numbers. This is required.
.PARAMETER fileColumn
Column title in CSV file containing SerialNumber values. This is optional, with a default value of "SerialNumber".
.PARAMETER deviceColumn
Column title in CSV file containing DeviceName values. This is optional, with a default value of "DeviceName".
.PARAMETER searchBy
Type of Id to search by. This is optional, with a default value of "SerialNumber".
.INPUTS
AirWatchConfig.json
CSV File with headers
Expand Down
2 changes: 1 addition & 1 deletion Get-Profiles.ps1 → Get-Profile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Update Date: 01/09/2021
Site: https://github.com/MrTechGadget/aw-bulkdevices-script
.EXAMPLE
.\Get-Profiles.ps1 -query "status=Active&platform=Apple"
.\Get-Profile.ps1 -query "status=Active&platform=Apple"
#>


Expand Down
21 changes: 19 additions & 2 deletions PSairwatch.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ Function Send-Get {
Write-Warning "Error submitting Get. $($_.Exception.Message) "
return $webReturn
}

}

Function Send-Post {
Expand All @@ -362,7 +361,6 @@ Function Send-Post {
Write-Warning "Error submitting POST. $($_.Exception.Message) "
return $webReturn
}

}

Function Send-Put {
Expand All @@ -385,7 +383,26 @@ Function Send-Put {
Write-Warning "Error submitting PUT. $($_.Exception.Message) "
return $webReturn
}
}

Function Send-Delete {
Param(
[Parameter(Mandatory=$True,HelpMessage="Rest Endpoint for Delete, after https://airwatchServer/api/")]
[string]$endpoint,
[Parameter(HelpMessage="Version of API")]
[string]$version = $version1
)
$headers = Set-Header $restUserName $tenantAPIKey $version "application/json"
try {
$endpointURL = "https://${airwatchServer}/api/${endpoint}"
$webReturn = Invoke-RestMethod -Method Delete -Uri $endpointURL -Headers $headers

return $webReturn
}
catch {
Write-Warning "Error submitting Delete. $($_.Exception.Message) "
return $webReturn
}
}

Function Set-DeviceIdList {
Expand Down
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,31 @@ EXAMPLE
file parameter (REQUIRED) is the path to a CSV file with a list of Serial Numbers. fileColumn parameter (OPTIONAL, with a default value of "SerialNumber") is the Column title in CSV file containing SerialNumber values.
The user is prompted to confirm before it is executed. A progress bar shows progress through all of devices, and output to the window and a log file shows successes and failures of each device, as well as any errors.

EXAMPLE
Reset-EnterpriseWipe.ps1 -file "Devices.csv" -fileColumn "SerialNumber"

**Get-DeviceDetails.ps1** - Gets Device Details given a list of SerialNumbers and Desired names.
file parameter (REQUIRED) is the path to a CSV file with a list of Serial Numbers. fileColumn parameter (OPTIONAL, with a default value of "SerialNumber") is the Column title in CSV file containing SerialNumber values. searchBy parameter (OPTIONAL, with a default value of "SerialNumber") is the type of identification number to use in search.

EXAMPLE
Reset-EnterpriseWipe.ps1 -file "Devices.csv" -fileColumn "SerialNumber"
Get-DeviceDetails.ps1 -file "Devices.csv" -fileColumn "SerialNumber"

**Get-Profile.ps1** - Gets Profiles with optional query parameters to limit results.
Optional query parameters to refine search. For values, refer to API documentation. https://as135.awmdm.com/api/help/#!/apis/10003?!/ProfilesV2/ProfilesV2_Search
Multiple parameters should be joined with "&"

EXAMPLE
Get-Profiles.ps1 -query "status=Active&platform=Apple"

**Delete-Profile.ps1** - Deletes Profiles given a list of Profile IDs.
file parameter (REQUIRED) is the path to a CSV file with a list of Profile IDs.
fileColumn parameter (OPTIONAL, with a default value of "ProfileId") is the Column title in CSV file containing ProfileId values.
EXAMPLE
Delete-Profile.ps1 -file .\ProfilesTest.csv -fileColumn "ProfileId"

## Compatibility

These PowerShell scripts are PowerShell Core (PS 6) compliant and were written with Visual Studio Code on a Mac.
These PowerShell scripts are PowerShell Core (PS 6+) compliant and were written with Visual Studio Code on a Mac.

They have been tested on Windows and Mac, but should also run on Linux.

Expand Down

0 comments on commit 53277ed

Please sign in to comment.