Skip to content

Commit

Permalink
Merge pull request #12 from MrTechGadget/RebootDevice
Browse files Browse the repository at this point in the history
Implemented Reboot Device script
  • Loading branch information
MrTechGadget committed Oct 7, 2020
2 parents d913bf2 + 5f473ae commit 9c87ea2
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
86 changes: 86 additions & 0 deletions Invoke-RebootDevice.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<#
.SYNOPSIS
Reboots devices given a list of SerialNumbers.
.DESCRIPTION
Reboots devices given a list of SerialNumbers. Uses the Command API to SoftReset (reboot) the device.
.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
CSV File with headers
.OUTPUTS
NO OUTPUT CURRENTLY:Outputs a CSV log of actions
.NOTES
Version: 1.0
Author: Joshua Clark @MrTechGadget
Creation Date: 09/30/2020
Update Date: 10/05/2020
Site: https://github.com/MrTechGadget/aw-bulkdevices-script
.EXAMPLE
.\Invoke-RebootDevice.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

$Logfile = "$PSScriptRoot\RebootDevice.log"

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

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

$list = Read-FileWithData $file $fileColumn

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

$decision = $Host.UI.PromptForChoice(
"Attention! If you proceed, " + @($list).count + " devices will be rebooted",
"",
@('&Yes', '&No'), 1)

if ($decision -eq 0) {
Write-Log "Rebooting $($list.count) devices in AirWatch"
$devices = @()
foreach ($item in $list) {
$devices += $item.$($fileColumn)
}
$json = Set-AddTagJSON $devices
Write-Progress -Activity "Rebooting Devices..." -Status "$($list.Count) devices"
$endpointURL = "mdm/devices/commands/bulk?command=SoftReset&searchby=SerialNumber"
try {
$result = Send-Post -endpoint $endpointURL -body $json -version $version1
if ($result -eq "") {
$err = ($Error[0].ErrorDetails.Message | ConvertFrom-Json)
Write-Warning ("Error Rebooting Devices : Error", $err.errorCode, $err.message)
Write-Log ("Error Rebooting Devices : Error", $err.errorCode, $err.message)
}
else {
Write-Host "$result"
Write-Log "$result"
}
}
catch {
$err2 = ($Error[0].ErrorDetails.Message)
Write-Warning "Error Rebooting Devices $err2"
Write-Log "Error Rebooting Devices $err2"
}
}
else {
Write-Host "Action Cancelled"
Write-Log "Action Cancelled"
}

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ Given this is a synchronous API call, the list is broken into batches of 50 per
EXAMPLE
Delete-User.ps1 -userFile "User.csv" -userFileColumn "Id.Value"

**Invoke-RebootDevice.ps1** - Reboots devices given a list of SerialNumbers. Uses the Command API to SoftReset (reboot) the device.
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. Output to the window and a log file shows successes and failures of devices, as well as any errors.

EXAMPLE
Invoke-RebootDevice.ps1 -file "Devices.csv" -fileColumn "SerialNumber"

**Reset-FullDevice.ps1** - This script executes a full device wipe for a CSV list of serial numbers.
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.
Expand Down

0 comments on commit 9c87ea2

Please sign in to comment.