The Problem
For any new machines ordered from a vendor such as Dell that get enrolled into Autopilot you get the basic device info enrolled but nothing defining that would let it get auto-enrolled into a dynamic group easily. Purchase Order ID is included in every order we receive from Dell however I don’t want to have to add that Purchase Order ID into the dynamic device query every time a new machine gets added.
Instead assigning a Group Tag would be much more beneficial. I won’t have to change the dynamic device query and won’t run the risk of messing the group up.
Watch a demo of this script on Intune.Training.
https://youtu.be/VCR-J5pvQbo
Requirements
- Access to Create Groups in (AAD) Azure Active Directory
- Access to create an Application in AAD
- Access to grant admin consent for your organization
- Access to Intune
Creating a Dynamic Device Group
- Navigate to your Intune portal
- Select Groups
- Select New Group
- Group Type should be Security
- Assign a group name “Intune Windows Device Enrollment”
- Membership type should be changed to Dynamic Device
- Select Add dynamic query
- On Rule Syntax Select Edit on the right hand side
- Type in the following:
(device.devicePhysicalIds -any _ -contains "StandardMachine")
- Feel free to change
"StandardMachine"
to whatever you’d like your group tag to be - Select Save
- Select Create
Registering an APP to access Graph API and Grabbing Additional Information
- Navigate to your Azure Active Directory
- Select App registrations
- Select New registration
- Give your app a name such as Intune Graph Access
- Select Register
- Go to your newly created App
- Select API permissions
- Select Add a permission
- Select Microsoft Graph
- Select Application permissions
- Enable DeviceManagementServiceConfig.ReadWrite.All
- Select Add permissions
- Select Grant Admin Consent for CONTOSO
- Navigate to Certificates & Secrets for your app
- Select New client secret
- Give a description and select an expiration time
- Select Add
- Copy the key value for later use
- Select Overview
- Copy the Application (client) ID for later use
- Select Custom domain names
- Copy your domain that has the .onmicrosoft.com for later use
The Script
You will need to update 4 fields in the below script with information you copied earlier. Those fields being line 2,3,4, and 6 if you changed the group tag for your dynamic device query. The script will use the App we created earlier to authenticate and grab information for all devices and create an array of devices based on Purchase Order ID. that you manually enter via prompt. It then loops through that array and assigns the Group Tag to all devices . Once all group tags have been assigned it will push a refresh to your portal, bare in mind that you may have to wait an hour or so for the new group tags to show up. This is incredibly helpful for large bulk orders.
|
|
Jake Shackelford Admin/Contributor
Jake is one of our Admins but also our inaugural author and the main reason SysManSquad exists today.