Skip to content

Instantly share code, notes, and snippets.

@rayterrill
Created May 15, 2017 23:02
Show Gist options
  • Select an option

  • Save rayterrill/e83a1bd877547eccfd59b656e7f91b48 to your computer and use it in GitHub Desktop.

Select an option

Save rayterrill/e83a1bd877547eccfd59b656e7f91b48 to your computer and use it in GitHub Desktop.
# Ensure the build fails if there is a problem.
# The build will fail if there are any errors on the remote machine too!
$ErrorActionPreference = 'Stop'
$user = 'MYADMINUSER'
$password = $env:MYADMINPASSWORD
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$password)))
$server = "https://MSERVER.MYDOMAIN.COM"
$phoneNumber = $env:PhoneNumber
$labelToRemove = [uri]::EscapeDataString($env:LabelsToRemove)
$labelToAdd = [uri]::EscapeDataString($env:LabelsToAdd)
#find the uuid by phone number
$url = "$($server)/api/v2/devices?count=50&offset=0&fields=common.uuid&labelId=-1&query=$($phoneNumber)&page=1&start=0&limit=50&adminDeviceSpaceId=1"
#uuid is stored in $deviceID.results."common.uuid"
$deviceID = Invoke-RestMethod -uri $url -Method Get -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
#remove a label from a device
$url = "$($server)/api/v1/dm/labels/$($labelToRemove)/$($deviceID.results.'common.uuid')?action=remove"
$results = Invoke-RestMethod -uri $url -Method PUT -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
#force a check-in
$url = "$($server)/api/v1/dm/devices/wakeup/$($deviceID.results.'common.uuid')"
$results = Invoke-RestMethod -uri $url -Method GET -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
#add a label to a device
$url = "$($server)/api/v1/dm/labels/$($labelToAdd)/$($deviceID.results.'common.uuid')?action=apply"
$results = Invoke-RestMethod -uri $url -Method PUT -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
#force a check-in
$url = "$($server)/api/v1/dm/devices/wakeup/$($deviceID.results.'common.uuid')"
$results = Invoke-RestMethod -uri $url -Method GET -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment