{"id":1348,"date":"2016-05-19T20:12:06","date_gmt":"2016-05-20T00:12:06","guid":{"rendered":"http:\/\/www.briandeyo.us\/brd\/wp\/?p=1348"},"modified":"2016-05-19T20:12:06","modified_gmt":"2016-05-20T00:12:06","slug":"airwatch-rest-api-script-change-self-service-portal-role-for-users","status":"publish","type":"post","link":"https:\/\/www.briandeyo.us\/index.php\/2016\/05\/19\/airwatch-rest-api-script-change-self-service-portal-role-for-users\/","title":{"rendered":"AirWatch REST API Script : change Self-Service Portal role for users"},"content":{"rendered":"<p>Here&#8217;s several scripts that may be very helpful for anyone that needs to change the self-service portal role for their users in AirWatch. AirWatch is becoming more robust and mature with every new release, but they still have a long way to go towards overall usability for administrators.<\/p>\n<hr \/>\n<p>&nbsp;<\/p>\n<p>#******************************************<br \/>\n### AirWatch API Connection<br \/>\n###<br \/>\n### Template from https:\/\/support.air-watch.com\/posts\/94020718-REST-API-Authentication-in-PowerShell<br \/>\n###<br \/>\n### 2015-11-15 Brian Deyo www.briandeyo.us<br \/>\n#*******************************************<\/p>\n<p>write-output &#8221; __ ___ __ &#8221;<br \/>\nwrite-output &#8221; \/\\ | |__) | | \/\\ | \/ &#8220; |__| &#8221;<br \/>\nwrite-output &#8221; \/~~\\ | | \\ |\/\\| \/~~\\ | \\__, | | &#8221;<br \/>\nwrite-output &#8221; &#8221;<\/p>\n<p>###############################<br \/>\n###<br \/>\n### BEGIN CONFIGURATION SECTION<br \/>\n###<br \/>\n###############################<\/p>\n<p>###Insert AirWatch API Key here<br \/>\n###Consider it best practice to create an API Key for every account that needs API access. Easier to manage access that way.<br \/>\n###<br \/>\n$APIKEY = &#8220;blahblahblahAPIKey&#8221;<\/p>\n<p>###Insert AirWatch Application Server URL<br \/>\n###The Server is the &#8220;Application Server&#8221; component of the AirWatch environment.<br \/>\n###<br \/>\n$AWHost = &#8220;xxyyy.awmdm.com\/API\/v1&#8221;<\/p>\n<p>###Pop up to get username and password, and then encodes U &amp; P to string<br \/>\n###<br \/>\n$Credential = Get-Credential<br \/>\n$EncodedUsernamePassword = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($(&#8216;{0}:{1}&#8217; -f $Credential.UserName,$Credential.GetNetworkCredential().Password)))<\/p>\n<p>###Define Headers to send with each API access<br \/>\n###Switch Basic to Directory if using AD integrated account<br \/>\n###<br \/>\n$Headers = @{&#8216;Authorization&#8217; = &#8220;Basic $($EncodedUsernamePassword)&#8221;;&#8217;aw-tenant-code&#8217; = &#8220;$APIKey&#8221;;&#8217;Content-type&#8217; = &#8216;application\/json&#8217;}<\/p>\n<p>###Define output folder for Rest Logs when the out-file cmdlet is used<br \/>\n###<br \/>\n$RestLogPath = &#8220;\\\\fileshare\\log\\location&#8221;<\/p>\n<p>###############################<br \/>\n###<br \/>\n### END CONFIGURATION SECTION<br \/>\n###<br \/>\n###############################<\/p>\n<p>#***********************************<br \/>\n# List devices for a specific user<br \/>\n#***********************************<br \/>\n#<br \/>\n#write-output &#8220;Type User&#8217;s email address&#8221;<br \/>\n#$UserEmail = Read-Host<br \/>\n#Invoke-RestMethod -Method Get -Uri https:\/\/$AWHost\/mdm\/devices\/search?user=$UserEmail -Headers $Headers<\/p>\n<p>#***********************************<br \/>\n# Set Enrollment User&#8217;s SSP Access<br \/>\n#***********************************<br \/>\n#<br \/>\n# Define the JSON in the $body variable. Then the Invoke-RestMethod converts to JSON on the fly<br \/>\n#<br \/>\n#$Role = &#8220;SSP ROLE NAME&#8221;<br \/>\n#$user = &#8220;userID&#8221;<br \/>\n#$body = @{<br \/>\n# Role = $Role<br \/>\n# }<br \/>\n#Invoke-RestMethod -Method Post -Uri https:\/\/$AWHost\/system\/users\/$user\/update -Body (ConvertTo-Json $body) -Headers $Headers<\/p>\n<p>#***********************************<br \/>\n# Get Enrollment User Details<br \/>\n#***********************************<br \/>\n#$user = Read-Host<br \/>\n#$Filename = &#8220;UserDetails.txt&#8221;<br \/>\n#Invoke-RestMethod -Method Get -Uri https:\/\/$AWHost\/system\/users\/$user -Headers $Headers | Out-File -Append $RestLogPath$Filename<\/p>\n<p>#***********************************<br \/>\n# Change a single Users SSP Role<br \/>\n#***********************************<\/p>\n<p>#$User = Read-Host<br \/>\n#$NewRole = &#8220;SSP ROLE NAME&#8221;<br \/>\n#$body = @{<br \/>\n# Role = $NewRole<br \/>\n# }<br \/>\n#Invoke-RestMethod -Method Post -Uri https:\/\/$AWHost\/system\/users\/$User\/update -Body (ConvertTo-Json $body) -Headers $Headers<\/p>\n<p>#*************************************************************<br \/>\n# Search for All Users that have specific role and change it<br \/>\n#*************************************************************<br \/>\n#$CurrentRole = &#8220;SSP ROLE NAME&#8221;<br \/>\n#$Filename = &#8220;SSP ROLE NAME.txt&#8221;<br \/>\n#$UserList = Invoke-RestMethod -Method Get -Uri https:\/\/$AWHost\/system\/users\/search?role=$CurrentRole -Headers $Headers<br \/>\n#$list = $UserList.Users.Id<br \/>\n###Save output of every UserID getting changed<br \/>\n#$list.value | Out-File $RestLogPath$Filename<br \/>\n#<br \/>\n### Loop to change all the roles from the dumped list<br \/>\n#<br \/>\n#$NewRole = &#8220;SSP ROLE NAME&#8221;<br \/>\n#foreach ($User in $list)<br \/>\n#{<br \/>\n# $UserToUpdate = $User.value<br \/>\n#<br \/>\n# $body = @<br \/>\n# {<br \/>\n# Role = $NewRole<br \/>\n# }<br \/>\n# Invoke-RestMethod -Method Post -Uri https:\/\/$AWHost\/system\/users\/$UserToUpdate\/update -Body (ConvertTo-Json $body) -Headers $Headers<br \/>\n#}<\/p>\n<p>#************************************<br \/>\n# List Number of Users in Each Role<br \/>\n#************************************<br \/>\n#$RolesToCheck = @(&#8220;Basic Access&#8221;,&#8221;External Access&#8221;,&#8221;Full Access&#8221;)<br \/>\n#Foreach ($Role in $RolesToCheck)<br \/>\n#{<br \/>\n# $Filename = &#8220;$Role &#8211; TOTALS.txt&#8221;<br \/>\n# $UserList = Invoke-RestMethod -Method Get -Uri https:\/\/$AWHost\/system\/users\/search?role=$Role -Headers $Headers<br \/>\n# $list = $UserList.Users.Id<br \/>\n# ###Save output of every UserID getting changed<br \/>\n# $UserList | Tee-Object $RestLogPath$Filename<br \/>\n#}<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s several scripts that may be very helpful for anyone that needs to change the self-service portal role for their users in AirWatch. AirWatch is becoming more robust and mature with every new release, but they still have a long way to go towards overall usability for administrators. &nbsp; #****************************************** ### AirWatch API Connection ### &hellip;<\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,306,10,307],"tags":[308,310,309,276,12,311],"class_list":["post-1348","post","type-post","status-publish","format-standard","hentry","category-mobile-devices","category-scripting","category-tech","category-workspace_one","tag-airwatch","tag-api","tag-rest","tag-script","tag-scripting","tag-ssp"],"_links":{"self":[{"href":"https:\/\/www.briandeyo.us\/index.php\/wp-json\/wp\/v2\/posts\/1348","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.briandeyo.us\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.briandeyo.us\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.briandeyo.us\/index.php\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.briandeyo.us\/index.php\/wp-json\/wp\/v2\/comments?post=1348"}],"version-history":[{"count":3,"href":"https:\/\/www.briandeyo.us\/index.php\/wp-json\/wp\/v2\/posts\/1348\/revisions"}],"predecessor-version":[{"id":1351,"href":"https:\/\/www.briandeyo.us\/index.php\/wp-json\/wp\/v2\/posts\/1348\/revisions\/1351"}],"wp:attachment":[{"href":"https:\/\/www.briandeyo.us\/index.php\/wp-json\/wp\/v2\/media?parent=1348"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.briandeyo.us\/index.php\/wp-json\/wp\/v2\/categories?post=1348"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.briandeyo.us\/index.php\/wp-json\/wp\/v2\/tags?post=1348"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}