/
/

How to Automate Intune Configuration Profile Assignments Based on Device Labels via Graph API

by Angelo Salandanan, IT Technical Writer
How to Automate Intune Configuration Profile Assignments Based on Device Labels via Graph API blog banner image
How to Automate Intune Configuration Profile Assignments Based on Device Labels via Graph API blog banner image

Key Points

  • Automate Intune configuration profile assignments via Microsoft Graph API using a Label → Group → Profile workflow: tag devices, query them by label, add them to a matching group, then assign the profile to that group.
  • Prerequisites: Intune licensing, Microsoft Entra ID Premium, PowerShell 7+ with the Microsoft.Graph module, and an app registration with DeviceManagementConfiguration.ReadWrite.All, Device.Read.All, and Group.ReadWrite.All permissions.
  • Intune only supports group-based assignments, so devices must be added to an Entra ID group (dynamic or manually managed) before a configuration profile can be applied.
  • Use one authoritative label source, registry key, Intune DeviceCategory, or Entra extension attribute, to avoid duplicate or unassigned devices; Intune applies “last writer wins” if a device has multiple labels.
  • Run the workflow on a recurring schedule and log assignment status back to the registry for audit tracking, so new or changed devices are picked up automatically.

Onboarding devices and assigning user groups are two common actions that MSPs and enterprise IT teams look to automate to improve workflow. At scale, this is typically configured via RMM or Intune configuration profiles, which use device labels via Graph API. Explore our guide to get started.

Looking for a visual guide to enhance your understanding? Watch our video: How to Automate Intune Configuration Profile Assignments Based on Device Labels via Graph API.

Steps for setting Intune configuration profile assignments via Graph API

Use the table to choose and quickly navigate to your preferred activation steps.

📌 Prerequisites:

  • Microsoft Intune licenses
  • Microsoft Entra ID Premium (for dynamic groups and Intune policies)
  • Registered application with Graph API permissions:
    • ReadWrite.All(For Settings Catalog policies)
    • ReadWrite.All (For standard configuration profiles)
    • Read.All (Required to read Intune device categories)
    • ReadWrite.All (To manage assignment groups)
  • PowerShell 7+ with Microsoft.Graph module
  • Optional: Local registry access for tagging
  • Optional: NinjaOne or RMM platform for endpoint metadata and script execution

💡 Tip: Check out the Things to look out for section for tips on managing potential risks.

Step 1: Apply local registry-based device labels (Optional)

In this example, a simple registry key on each device is created with values like Label=Finance and AssignedProfile=None.

  1. Use Search 🔎 to open Terminal → PowerShell → Run as administrator.
  2. Tag endpoints with role or environment metadata:

Set-ItemProperty -Path “HKLM:\SOFTWARE\Org\DeviceLabels” -Name “Label” -Value “Finance”

Set-ItemProperty -Path “HKLM:\SOFTWARE\Org\DeviceLabels” -Name “AssignedProfile” -Value “None”

This step can be used with Intune or alongside it as you transition. It creates a simple registry key on each device, which also serves as metadata.

You may run reg query HKLM\SOFTWARE\Org\DeviceLabels in CMD or PowerShell for validation. These labels can guide which Intune profile should be assigned by an external script logic.

Step 2: Connect to Microsoft Graph and query devices by label

These scripts tag devices by a label (e.g., DeviceCategory -eq “Finance”) or via extension attributes, like Entra ID extension properties.

  1. Use Search 🔎 to open Terminal → PowerShell → Run as administrator.
  2. Connect to Graph:

Connect-MgGraph -Scopes “DeviceManagementManagedDevices.Read.All”, “Group.ReadWrite.All”

  1. Then, query devices by category:

$devices = Get-MgManagedDevice | Where-Object { $_.DeviceCategory -eq “Finance” }

If you’re using extension attributes, adjust the query to match those instead. Intune and Entra ID are best used to target enrolled devices.

⚠️ Technical Note: Ensure your automation targets the ManagedDevice endpoint rather than the standard Entra ID Device endpoint. Intune-specific attributes, such as DeviceCategory, do not exist on default Entra ID objects. Querying the wrong endpoint will result in an empty dataset.

Step 3: Create or find configuration profiles and assign them by group

The next objective is to ensure there’s a target group for the label (e.g., “Finance Devices”).

  1. Use Search 🔎 to open Terminal → PowerShell → Run as administrator.
  2. Run Get-MgDeviceManagementDeviceConfiguration to list existing configuration profiles.
  3. Then, find or create an assignment group for the target label:

$group = Get-MgGroup | Where-Object { $_.DisplayName -eq “Finance Devices” }

Or create a new group:

$group = New-MgGroup -DisplayName “Finance Devices” -MailEnabled:$false `

-MailNickname “FinanceGroup” -SecurityEnabled:$true

  1. With the group created, you can add devices to the group and assign a configuration profile.
    • Add devices: 

Add-MgGroupMember -GroupId $group.Id -DirectoryObjectId $device.Id

    • Assign configuration profile:

New-MgDeviceManagementDeviceConfigurationAssignment `

-DeviceConfigurationId $configProfile.Id `

-Target @{groupId = $group.Id}

🧠 Structural Requirement: When assigning a configuration profile via the Graph API, the system requires an explicit @odata.type structural wrapper. The script must explicitly define the target as a #microsoft.graph.groupAssignmentTarget and pass the Group ID inside that specific payload structure, rather than applying it directly to the profile object.

💡 Note: Additionally, you can use dynamic membership if your label is stored in a group-queryable attribute (e.g., extension attribute). Otherwise, you automate the tagging via RMM.

Step 4: Automate the workflow (Label → Group → Profile)

This step is all for setting hands-off management once the label sources and target profiles have been duly identified and queried. Here’s a sample script using the previous labels and profiles:

$label = “Finance”

$devices = Get-MgDevice | Where-Object { $_.DeviceCategory -eq $label }foreach ($device in $devices) {

$group = Get-MgGroup | Where-Object { $_.DisplayName -eq “$label Devices” }if (-not $group) {

$group = New-MgGroup -DisplayName “$label Devices” -MailEnabled:$false `

-MailNickname “$labelGroup” -SecurityEnabled:$true}Add-MgGroupMember -GroupId $group.Id -DirectoryObjectId $device.IdNew-MgDeviceManagementDeviceConfigurationAssignment `

-DeviceConfigurationId $configProfile.Id `

-Target @{groupId = $group.Id}}

In managed and enterprise environments, this script must be run on a recurring basis to pick up new endpoints that need to be organized.

Step 5: Store assignment status for audit in the registry

To close, update the registry to track which profile has been applied. You can run the following script via PowerShell:

Set-ItemProperty -Path “HKLM:\SOFTWARE\Org\DeviceLabels” -Name “AssignedProfile” -Value “Finance_Profile”

Set-ItemProperty -Path “HKLM:\SOFTWARE\Org\DeviceLabels” -Name “LastSynced” -Value (Get-Date).ToString(“u”)

This action creates a local audit trail for support teams. This data can also be collected by an RMM or exported to CSV for central reporting.

💡 Note: This script may run or fail without displaying any confirmation or prompt. To confirm if changes have been applied successfully, check the corresponding registry keys or system settings.

Quick-Start Guide

NinjaOne can help with Intune configuration profile assignments based on device labels via Graph API, though the specifics may require some custom scripting or automation. Here are the key insights:

1. NinjaOne supports device management and has integration capabilities with Microsoft technologies.

2. The platform offers:

  • Device labeling
  • Automated device configurations
  • Support for PowerShell and API-based automation

3. While there’s no direct out-of-the-box solution for Intune profile assignments, you can achieve this through:

⚠️ Things to look out for when automating Intune profile assignments

Below are common risks, their possible consequences, and some practical ways to reverse or prevent issues.

RisksPotential ConsequencesReversals
Inconsistent labeling sources (local registry vs. Intune DeviceCategory vs. Entra extension attributes)Devices may not be grouped correctly; duplicates or unassigned machinesStandardize on one authoritative label source; if migrating, add safeguards to prevent duplicate assignments
Creating dynamic groups without a stable attributeGroup rules never resolve; devices never receive profilesEnsure labels are stored in an attribute usable in dynamic rules (e.g., extensionAttribute, deviceCategory); test rules on a sample set
Graph throttling in large environmentsScript execution slows; partial device updatesBatch devices, add retry logic, or run the workflow label-by-label instead of all at once

Some of the earlier challenges in automating profile assignments via Intune happen in transitions. So, it’s best to do due diligence to ensure labels and groupings don’t conflict or get duplicated.

Also, the scripts may need to be run staggered in large environments, unless you’re running them via an RMM that fits the scale of the operation.

Use NinjaOne to enhance Intune workflows

Many Intune workflows can be layered with automation policies, reporting, and both scalable and granular IT management offered by NinjaOne RMM®.

  • Deploying scripts that tag devices in the registry
  • Triggering external Graph scripts via automation policies
  • Reporting on device metadata (label, role, location) to guide assignments
  • Tagging devices without proper configuration profiles for remediation
  • Alerting when devices drift from expected Intune policy assignments

With NinjaOne, MSPs can streamline Intune policy governance while maintaining multi-client scalability and reporting.

Best practices for automating profile assignment in Intune

Enabling Intune configuration profile assignment automation with Graph API is an effective way to promote policy enforcement and streamline device onboarding across your network.

But as your organization grows, consider pairing Intune and Graph API with an RMM NinjaOne, which offers automation and remediation capabilities at scale. This proactive approach provides a complete framework for hands-off, audit-ready, and scalable endpoint management.

Related topics:

FAQs

Intune configuration profiles are collections of settings and policies that control security, hardware restrictions, and operating system behavior across managed endpoints. These profiles are assigned to user or device groups to enforce standardized baselines across an environment.

Microsoft Graph API is the unified gateway to Microsoft 365 services. Because the Microsoft Intune admin center is built entirely on top of Graph API API endpoints, administrators can use it to programmatically automate tenant deployment, query device states, and assign policies at scale.

If you want a 100% cloud-native workflow, you can bypass local registry keys entirely. You can rely on native Intune Device Categories or utilize Microsoft Entra ID Extension Attributes to build your dynamic targeting. Local registry keys are typically used when you need an on-premise RMM engine (like NinjaOne) to bridge the gap for unmanaged or transitioning endpoints.

If a device receives two conflicting configuration profile settings via different group assignments, Intune does not follow a “last writer wins” rule. Instead, it flags a Conflict state in the admin center, and neither setting is applied until an administrator manually resolves the overlap. To prevent this, ensure your script logic enforces a strict “one label per policy domain” architecture.

Microsoft Intune relies on group-based targeting architectures for custom compliance and configuration policies. While the platform allows you to target broad virtual collections like “All Devices,” granular targeting based on unique attributes or operational labels requires grouping objects first. This makes Microsoft Entra ID groups the necessary functional bridge for Graph API automation.

You might also like

Ready to simplify the hardest parts of IT?