-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from MrTechGadget/RebootDevice
Implemented Reboot Device script
- Loading branch information
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters