Skip to content

Instantly share code, notes, and snippets.

@HawaiiRyan
Last active April 1, 2020 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HawaiiRyan/0e43de0ec74ea8a2c358c365cf04bf73 to your computer and use it in GitHub Desktop.
Save HawaiiRyan/0e43de0ec74ea8a2c358c365cf04bf73 to your computer and use it in GitHub Desktop.
Google Chrome App Update Tool - Android
######Howto use script
# 1. Create config.ini file
# 1a. Config.ini file example at following URL: https://gist.github.com/HawaiiRyan/b610f6d5427afa9609cee145affed912
# 2. Update -path location in the line where variable/object $WS1Env is declared
# 3. Ensure $addy, $b64, $apikey are referencing the correct environment.
# 3a. UAT environment is used in this example
#Set Verbosity Preference
$VerbosePreference = "Continue"
$filepath = Get-Location
$WS1Env = Get-Content -Path $filepath\config.ini | Select -Skip 1 | ConvertFrom-StringData
#Require TLS 1.2 for communication
[Net.ServicePointManager]::SecurityProtocol =
[Net.SecurityProtocolType]::Tls12
#Workspace ONE Environment Address, Authentication, and Headers
$addy = $WS1Env.UATEnvironment
$b64 = $WS1Env.UATb64
$encodedString = "Basic " + $b64
$apiKey = $WS1Env.UATapikey
$useJSON = "application/json"
$headers = @{"Authorization" = $encodedString; "aw-tenant-code" = $apiKey; "Accept" = $useJSON; "Content-Type" = $useJSON }
#Param for function
$chromeapp = 'com.android.chrome'
Function Get-ChromeID {
#Begin function Get-Chrome
param([string]$chromeapp)
$chrome = Invoke-RestMethod -Uri "$addy/API/mam/apps/search?bundleid=com.android.chrome" -Headers $headers
Return $chrome.Application.Id.Value
}
#######################
###Chrome Update
$pubappid = Get-ChromeID
try {
Write-Verbose -Message "Setting up HTTP session"
#Get public devices assigned to Chrome application from Workspace ONE
$ServicePoint = [System.Net.ServicePointManager]::FindServicePoint($addy)
Write-Verbose -Message "Successfully opened service point connection"
$devid = Invoke-RestMethod -Uri "$addy/API/mam/apps/public/$pubappid/devices" -Headers $headers
$ServicePoint.CloseConnectionGroup("")
}
catch {
Write-Verbose -Message "Problem in API call, $_.Exception.Message received"
#Break
#Un-comment the line above to stop script if HTTP response of 202 not received it didn't work
}
#Get the deviceID for the device
$fixdevice = $devid.DeviceId
#Loop through the object foreach deviceID and try to invoke-restmethod on with the http request body containing the deviceID in JSON format
ForEach ($id in $fixdevice) {
$devicebody = @"
{"DeviceId": $id}
"@
try {
$ServicePoint = [System.Net.ServicePointManager]::FindServicePoint($addy)
Invoke-RestMethod -Method Post -Uri "$addy/API/mam/apps/public/$pubappid/install" -Headers $headers -Body $devicebody
Write-Host "$id is getting updated"
$ServicePoint.CloseConnectionGroup("")
}
catch {
Write-Verbose -Message "Problem in API call, $_.Exception.Message received"
#Break
#Un-comment the line above to stop script if HTTP response of 202 not received it didn't work
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment