Today I want to show you, how you can automatically set Intune Device Categories based on data already available in Intune / Entra, like Device Name, Device Model, Enrollment Profile Name, Join Type, etc.
I found a few articles that will try to do similar, but most of what I found did not scale well with many devices. My script will only modify devices where the desired category is different from the currently set category. For around 30k devices the initial run through all devices took me around 6-7h, where all subsequent runs are now only taking around 4-5mins.
Azure Automation Account
Let’s start with creating an Azure Automation Account, which will host and run our PowerShell script. I will start in a fresh Resource group:
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-41.png)
In our Resource group, we now can create our Automation Account from the Azure Marketplace:
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-42.png)
Search for “automation account” and click on “Create”
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-43.png)
Give it a name and set the desired Azure Region:
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-44.png)
In the Advanced Tab, make sure the system assigned managed identity is enabled:
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-45.png)
Once you finished the wizard, you can review your settings and we can start the deployment:
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-46.png)
Once finished, we can got to our newly created resource:
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-47-1024x340.png)
Runbook
In our Automation Account we can now go to the Runbooks section:
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-48.png)
And create our Runbook:
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-49-1024x690.png)
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-50.png)
In the new Runbook, we can add the script. You can find the script sample on my GitHub: https://github.com/mmeierm/Scripts/blob/main/Device%20Categories/DeviceCategory.ps1
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-51-1024x523.png)
Script
You will have to modify the script to match your needs to read the properties that you want to use as a basis for the categories. The script contains samples that reads device names, models, join type:
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-52.png)
It also contains samples to read data from Entra ID, like enrollmentProfileName or Autopilot GroupTag:
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-53.png)
The sample script itself follows the this logic:
-> Read in all Intune and active EntraID Devices
-> Loop through all Intune Devices
—>Check for Operating System Windows
—->Check virtual
——>Check DeviceName
——>Check Model
—-> Check phyiscal
——>Check DeviceName
——> Check Model
——> Check join Type
——> Search Entra Device
——–> Check enrollmentProfileName
——–> Check GroupTag
—>Check for Operating System MacOS
…
Once you are happy with your choice, you can save and publish the Runbook:
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-54.png)
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-55.png)
Assign Permissions
Next thing, that we need to do, is assigning the needed Graph API permissions to the managed identity. To get the needed object id, we can go to the Identity Tab in our Automation Account:
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-56.png)
Copy the Object ID:
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-57-1024x668.png)
And download the assign permissions script from GitHub: https://github.com/mmeierm/Scripts/blob/main/Device%20Categories/Add-Permission.ps1
And paste the object id and run it:
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-58-1024x365.png)
Device Categories
Last thing that we have to do, is the actual creation of the categories in Intune:
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-59-1024x499.png)
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-60.png)
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-61-1024x631.png)
Run the Script
Now, we can finally run our script:
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-62-1024x570.png)
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-63.png)
Conclusion
Automatically assign categories, can make the life of Intune Admins easier, as it allows them to easily filter for device groups in the portal:
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-64-1024x509.png)
You can also block your end users from changing the category by them self in the Customization settings:
![](https://mikemdm.de/wp-content/uploads/2024/06/grafik-65.png)
Leave a Reply