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.
Serial | GroupTag |
HE6LE7HO | Eggs |
CC3UDS1B | Jam |
YA03LDB7 | Jam |
JHXCTXV3 | Eggs |
5FUV285P | Jam |
0DR40TFL | Banana |
Example CSV for import.
Quick and dirty, but sufficient.
….assuming you have the necessary Graph permissions to be able to interact this way!
Leave a Reply