Bulk Assign Custom Security Attributes to Users in Entra ID

Prev Next

Tag users matching an email-domain filter with a Custom Security Attribute value for governance and Conditional Access scoping.

Complexity: Intermediate. Impact: identity-governance + bulk-operation + conditional-access + attribute-based-access-control.

Why use this workflow

Custom Security Attributes (CSAs) in Microsoft Entra ID are key-value pairs that you define at the tenant level to classify directory objects (users, service principals, devices). They are commonly used to drive Conditional Access scoping, attribute-based access control (ABAC) on Azure resources, license governance, and HR reporting.

A frequent operational task is the bulk assignment of a CSA value to a cohort of users, for example tagging every employee of a specific domain with Accounts > UserType = Employee so that they fall under the correct Conditional Access policy or ABAC role assignment. Assigning the value one user at a time in the Entra admin center is tedious and error-prone. This workflow shows the three paths you can use.

Run this workflow whenever you:

  • Onboard a new acquired domain and need to tag its users with a classification value.
  • Roll out a new CSA set and need to backfill existing users.
  • Periodically reconcile the CSA against a source of truth (HRIS, domain, group membership).

Expected outcomes

  • Every user matching the target filter (for example, mail ending in @contoso.com) carries the specified Custom Security Attribute value.
  • A reconciliation report that separates users who already had the attribute from users who were newly assigned.
  • An audit trail of the PATCH /beta/users/{id} calls, which you can review in the Entra audit log.
  • Confidence that Conditional Access policies, ABAC roles, or reports keyed on that attribute scope the tagged cohort correctly.

Risks and considerations

  • A privileged role is required. Assigning CSA values requires the Attribute Assignment Administrator role (or an equivalent custom role). Global Administrator alone is not sufficient. Grant the operator this role before you run the PATCH calls.
  • Beta endpoint. Custom Security Attribute read and write operations are on /beta. The payload shape may change when they move to v1.0.
  • PATCH merges, it does not replace. A partial customSecurityAttributes payload merges into the existing attribute set. To remove a value, send null explicitly.
  • Predefined values. If the attribute is configured with usePreDefinedValuesOnly = true, you must use an allowed value with isActive set to true. Free text fails.
  • Advanced queries. endsWith() requires the ConsistencyLevel: eventual header and $count=true. Without them, the filter returns HTTP 400.
  • Do not run the bulk assignment without first dry-running the filter and reviewing the user list. A typo in the domain filter can tag the wrong cohort.
  • Compliance. CSAs can hold data subject to internal governance (for example, employment classification). Confirm who can read the attribute set before you populate it. Visibility is governed by attribute-set-level permissions.

Required permissions

PermissionWhy it's needed
CustomSecAttributeDefinition.Read.AllRead the CSA definitions and allowed values to validate the attribute name and target value before assignment.
CustomSecAttributeAssignment.ReadWrite.AllRead and write Custom Security Attribute values on user objects.
User.Read.AllQuery users by mail filter to build the target cohort.
Attribute Assignment Administrator (directory role)Required in addition to the Graph scopes. The signed-in principal must hold this role to persist CSA writes.

Ask Dex

Paste the prompt into a Dex conversation.

Prompt for IT admins

Assign the Custom Security Attribute {attribute_set}.{attribute_name} = "{value}" to every user whose primary email ends with {mail_suffix}. Skip users who already have the value, produce a report of updated vs. skipped users, and confirm the assignments afterward.

Manual steps (admin center)

Use this path for small cohorts, or as a one-off verification after a scripted run.

Step 1: Confirm the attribute definition

  1. Sign in to the Microsoft Entra admin center as an Attribute Definition Reader (or higher).
  2. Go to Protection > Custom security attributes.
  3. Open the attribute set (for example, Accounts) and verify that the target attribute (for example, UserType) exists and that the desired value (for example, Employee) is listed as an active allowed value.

Step 2: Build the user cohort

  1. Go to Identity > Users > All users.
  2. Select Add filter, choose User principal name or Email, and enter the matching fragment (for example, @contoso.com).
  3. Export the filtered list with Download users so that you have a record of who was in scope.

Step 3: Assign the attribute per user

  1. Select a user in the filtered list to open their profile.
  2. Select the Custom security attributes tab.
  3. Select Add assignment.
  4. Choose the Attribute set (for example, Accounts), the Attribute name (for example, UserType), and the Value (for example, Employee).
  5. Select Save.
  6. Repeat for each user in the cohort.

Step 4: Verify

  1. Return to Users > All users, select Columns, and add Custom security attributes.
  2. Confirm that all targeted users display the expected attribute value.

For more than a handful of users, use the Graph API or PowerShell paths below. The admin center does not offer bulk selection for CSA assignment.

Microsoft Graph API

All CSA operations are on the /beta endpoint.

1. List attribute definitions (validate the target)

GET https://graph.microsoft.com/beta/directory/customSecurityAttributeDefinitions

Response (abbreviated):

{
  "value": [
    {
      "id": "Accounts_UserType",
      "attributeSet": "Accounts",
      "name": "UserType",
      "type": "String",
      "status": "Available",
      "usePreDefinedValuesOnly": true
    }
  ]
}

2. List allowed values for the attribute

GET https://graph.microsoft.com/beta/directory/customSecurityAttributeDefinitions/Accounts_UserType/allowedValues

Confirm that the target value (for example, Employee) is present with isActive: true.

3. Query the target users (advanced query)

GET https://graph.microsoft.com/v1.0/users?$filter=endsWith(mail,'@contoso.com')&$select=id,displayName,mail&$count=true
ConsistencyLevel: eventual

The ConsistencyLevel: eventual header and $count=true are required for endsWith().

4. PATCH each user to assign the attribute

PATCH https://graph.microsoft.com/beta/users/{user-id}
Content-Type: application/json

{
  "customSecurityAttributes": {
    "Accounts": {
      "@odata.type": "#microsoft.graph.customSecurityAttributeValue",
      "UserType": "Employee"
    }
  }
}

Expected response: HTTP 204 No Content.

5. Verify

GET https://graph.microsoft.com/beta/users/{user-id}?$select=displayName,customSecurityAttributes

Notes

  • Graph does not support $filter on customSecurityAttributes. Retrieve the candidates and filter client-side.
  • PATCH merges at the attribute-set level. Sending UserType: null clears only that attribute. Sending Accounts: null clears the entire set.
  • Use $batch to group PATCH calls and reduce round-trips.

PowerShell

PowerShell can automate the full workflow: authenticate, validate the attribute definition, enumerate the target cohort, skip users who are already tagged, and assign the CSA to the rest with a per-user success and failure report.

Prerequisites

  • PowerShell 7 or later
  • The Microsoft.Graph module installed (Install-Module Microsoft.Graph -Scope CurrentUser)
  • The signed-in admin must hold the Attribute Assignment Administrator directory role

Approach

  1. Connect to Graph with the minimum scopes required:
    Connect-MgGraph -Scopes "User.Read.All","CustomSecAttributeDefinition.Read.All","CustomSecAttributeAssignment.ReadWrite.All"
  2. Read the attribute definition and validate usePreDefinedValuesOnly. If it is true, confirm that the supplied value is an active allowed value.
  3. Query all users matching endsWith(mail, $MailSuffix) with the correct ConsistencyLevel header.
  4. Split the cohort into users who already have the value and users who need the assignment.
  5. Send a PATCH per user, collect the outcomes, and write a CSV report.
  6. Support a preview mode (for example, -WhatIf) so that you can review the changes before you apply them.