What is the best way to update a department name in Active Directory and Azure for 100+ users?

Viewed 27

Azure is currently setup to sync from on prem. Active Directory. What is the best way to update the department name in Active Directory and Azure for these users? Below is a sample of the list.

Name Old Department Name New Department Name
Larry Lue Collections Collector Members
Erica Anderson Collections Collector Members
Mary Lee Collections Collector Members
1 Answers

You can use ms graph api to do the update by code. But this api doesn't provide a batch operation, so you have to update user profile one by one. Here's my test result:

Before updating the department, the original department look like this:

enter image description here

After update it by code. it will be changed to the new value.

Here's the code snippet:

using Microsoft.Graph;
using Azure.Identity;

public async Task<IActionResult> IndexAsync()
{
    var scopes = new[] { "https://graph.microsoft.com/.default" };
    var tenantId = "tenant_name.onmicrosoft.com";
    var clientId = "azure_ad_app_id";
    var clientSecret = "azure_ad_app_client_secret";
    var clientSecretCredential = new ClientSecretCredential(
                    tenantId, clientId, clientSecret);
    var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
    
    //query user information
    var user = await graphClient.Users["user_id"]
        .Request().Select("displayname, department").GetAsync();

    //update user information
    var userDept = new User
    {
        Department = "Collector Members"
    };
    await graphClient.Users["9a8ae89f-711a-434a-8d08-43e1f7d29af2"]
        .Request()
        .UpdateAsync(userDept);
}
Related