Rubix

View Original

Group Tags, LIVE!

In the last post, we walked through a PowerShell script I created to enroll devices in Autopilot with a pop-up window to choose a group tag. This should be helpful for existing ‘one-off’ devices or testing different deployment profiles. Also, many of you asked me for the script itself as I only posted pieces of it last time; my bad. You can download the entire script here.

The biggest issue with my first run at this is how we aggregate the actual group tags. Basically, I created an XML file listing the tags, and used that to populate the list box form in PowerShell (yes, I realize the incredible ‘lameness’ of this). The optimal way would be to pull in the group tags directly from the Microsoft Graph. Fortunately, after consuming too much coffee after 9 pm last night, success was achieved.

First, rearrange

Here is the chunk from the first draft of the script that downloaded the group tag config file.

So first things first; we’re no longer going to be getting the XML file from a static location. Instead, we’re going to make a modified graph call to return active group tags. Note that this will only work on currently applied group tags.

Here is the graph call:

Get-AutopilotImportedDevice | select -ExpandProperty groupTag | Group-Object | % Name

Now our code to get the group tags from an XML file looks like this:

Because we’re still getting the tag content from an XML, we’re exporting our graph call as an XML file next to the script.

Next, move the modules

Because we’re using the Get-AutopilotImportedDevice function, we have to install and import our modules and authenticate to the graph BEFORE getting the tags. This function specifically comes from the WindowsAutopilotIntune module by Michael Niehaus. In the previous script, this was done later.

Before…

We need to move this block up above

After…

Finally, enjoy!

Now we will have authenticated prior to getting the tags, since they’re coming straight from the graph. Here is the new pop up:

So we’re getting the same options as before, just not as clean looking. Ultimately, I still have to do some work on getting rid of the null values, but this is at least functional.

The entire new script can be downloaded here. Let me know what you think.