Bulk Management of Tags on devices
This collection of scripts is used for bulk management of tags in an AirWatch environment.
https://github.com/MrTechGadget/aw-tag-script
Now this has grown to more than one script which are used to bulk manage tags within AirWatch.
Get-ListOfTaggedDevices.ps1 - This script displays all of the tags in the environment, the user selects a tag, and the device details for all devices with that tag are exported to a csv file with the name of the tag.
BulkTagActionsToDevices.ps1 - This script will take an input of serial numbers, converts them to device IDs. It queries a list of all Tags in the environment, the user selects the Tag to add the devices to and it adds the Tag in AirWatch for each of those devices.
These PowerShell scripts are PowerShell Core (PS 6) compliant and were written with Visual Studio Code on a Mac.
They have been tested on Windows and Mac, but should also run on Linux.
Setup: I am assuming you have a working way to run PowerShell scripts. If you need to set up your environment, check out this Getting Started post by Ashley McGlone
- These scripts take a config file, which houses the API Host, API key and Organization Group ID for your AirWatch environment. A sample file has been included, just remove the name sample and replace with your values. Name this file
AirWatchConfig.json
. Git will ignore this file.
{
"groupid" : 1234,
"awtenantcode" : "apikey",
"host" : "host.domain.tld"
}
- The
BulkTagActionsToDevices
script takes an input of serial numbers from aSerials.csv
file. Sample Included.
First, at first pass in seeing the need for the "Organization Group ID" I assumed the needed information was the group ID found under “Groups & Settings” > “Groups” > “Organization Groups” > “Organization Group Details”, but unfortunately it is not. When running the script and receiving the following output "\"ErrorMessage\":\"value must be a positive integer\"}]\r\n"," and then reviewing the AirWatchConfigSample.json file, we saw that the group id in the example has a numeric value. After digging for a bit we were able to find the numeric value for one of are OG's and successfully run the script. My guess is that a api call can only use a numeric value.
Secondly, our AirWatch deployment has multiple Organization Groups and even when using the top level OG group id the api query wasn't able to find devices that were in a lower level OG, I would receive the following error output "Invoke-RestMethod :{"ErrorCode":404,"Message":"Device not found for this request.",". We had to specify the numeric value of the group id where the devices serial number was located to get the script to successfully complete. I assumed that adding the top-level OG id would allow for device querying in sub-OG's, but when I was reviewing the powershell script I only saw the variable $organizationGroupID get used in the "Get-Tags" function in the variable $endpointURL and didn't see how it would block the sub-OG query.
Question, is the "Get-Tags" function there is only querying for available Tags in an OG or querying other data as well? I ask because I was working to modify in an effort to create a more automatic process, but wanted to understand the intent before.
I recently made and update to my big bulk actions scripts https://github.com/MrTechGadget/aw-bulkdevices-script that prompts the user for values and creates the config file if it doesn't already exist. I'll look at moving that over to this script as well soon.
If you want to discuss further on it, I've opened a new issue on GitHub for this. https://github.com/MrTechGadget/aw-tag-script/issues/6
Invoke-RestMethod : Device not configured
aw-tag-script/Get-ListOfTaggedDevices.ps1:118 char:18
+ ... webReturn = Invoke-RestMethod -Method Get -Uri $endpointURL -Headers ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Method: GET, Reques\u2026PowerShell/6.2.4
}:HttpRequestMessage) [Invoke-RestMethod], HttpRequestException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand