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

Sign in to be able to add comments.

Comments 9


MrTechGadget 2 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.
MrTechGadget 2 years ago
I stand corrected, it eventually syncs up with Github, just have to manually update the description.
StormFlowers 2 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.
simonelb 1 year 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?
MrTechGadget 1 year 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.
MomentOfTruth 7 months ago
hello: When trying to run this script an invalid URL error, it seems to cant find the Config file as well
MrTechGadget 7 months 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
andybrown2880 2 months ago
Thanks MrTechGadget the script works beautifully and save me from having to script it myself
MrTechGadget 2 months 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!
;