Bulk Update the GroupTag for Autopilot Devices

I just threw together a quick and dirty script to update the GroupTag assignments for Autopilot devices, based on a list of Serials (and GroupTag’s) stored in a CSV.

#James Vincent
#May 2024
#Bulk Update Autopilot GroupTag for Devices Stored in a CSV.

# Check if Microsoft.Graph module is installed
if (-not (Get-Module -Name Microsoft.Graph -ListAvailable)) {
    # Install Microsoft.Graph module
    Install-Module -Name Microsoft.Graph -Force -Scope CurrentUser
}

# Check if WindowsAutoPilotIntune module is installed
if (-not (Get-Module -Name WindowsAutoPilotIntune -ListAvailable)) {
    # Install WindowsAutoPilotIntune module
    Install-Module -Name WindowsAutoPilotIntune -Force -Scope CurrentUser
}

Connect-MgGraph -scopes "Group.ReadWrite.All, Device.ReadWrite.All, DeviceManagementManagedDevices.ReadWrite.All, DeviceManagementServiceConfig.ReadWrite.All, GroupMember.ReadWrite.All"

$DeviceList = Import-Csv -Path 'C:\Temp\Vin-AP-Serials.csv'

foreach($Device in $DeviceList)
{
    Write-Host "Changing Group tag for"$Device.Serial
    $APDevice = Get-AutopilotDevice -serial $Device.Serial 
    Set-AutopilotDevice -id $APDevice.id -groupTag $Device.GroupTag
    Write-Host "Group Tag for"$Device.Serial "Updated to"$Device.GroupTag
}

You just need to alter the path to your CSV.

The CSV needs two columns, one named Serial and the other GroupTag. The script will read the Serial, acquire the device information from Autopilot/Graph, and then update the GroupTag with whatever is referenced in the CSV.

SerialGroupTag
HE6LE7HOEggs
CC3UDS1BJam
YA03LDB7Jam
JHXCTXV3Eggs
5FUV285PJam
0DR40TFLBanana

Example CSV for import.

Quick and dirty, but sufficient.

….assuming you have the necessary Graph permissions to be able to interact this way!

James avatar

Leave a Reply

Your email address will not be published. Required fields are marked *