Bulk Management of Tags on devices

This collection of scripts is used for bulk management of tags in an AirWatch environment.


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 a Serials.csv file. Sample Included.

Sign in to be able to add comments.

Comments 12

3729165810 5 years ago
I recommend getting from GitHub linked above, I have made many improvements and it doesn't seem like those changes are syncing here despite this being connected to the Github repository.
3729165810 5 years ago
I stand corrected, it eventually syncs up with Github, just have to manually update the description.
4876323717 5 years ago
I have used this code and overall I'm happy with the function it provides, but I do have 2 notes and a question.

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.
2938592941 4 years ago
when i run the script it is stuck on "Please enter selection:" no matter what i use for input it will keep asking for the same input. Any idea on what i am doing wrong?
3729165810 4 years ago
simonelb, That prompt is waiting for you to enter the integer value next to the name of the tag in your environment, out of the list of tags it pulled from your environment. If you don't have any tags you won't have anything to select. Sounds like I need to add some checking for this case.
jbutler 4 years ago
hello: When trying to run this script an invalid URL error, it seems to cant find the Config file as well
3729165810 4 years ago
Jeff, did you create the Config file and name it "AirWatchConfig.json" If you haven't configured it, you will definitely get invalid URL errors because there is no host configured!

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
5328804977 3 years ago
Thanks MrTechGadget the script works beautifully and save me from having to script it myself
3729165810 3 years ago
Thanks @andybrown2880 I'm glad it is working for your needs. Let me know if there is anything I could add to make it better!
2791455533 3 years ago
I am getting an error when trying to run any or the PS scripts. Not sure what I'm missing

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

2791455533 3 years ago
Disregard my previous post, I figured it out - error with my URL
3729165810 3 years ago
Glad you figured it out, hope the scripts help you, let me know if I can do anything to improve them.