Azure AD Bulk User Updates

Azure AD Bulk User Actions

From time to time, we need to execute a collective action on Azure AD user accounts based on different needs. For example, let’s say that you decided to activate MFA company-wide, but your users do not have phone information in Azure AD. Or, let’s say you have decided to use a product like Sign & Go. You want your employees to include their titles in their signature, but in this case, opening Azure AD and editing everyone’s profile one by one is a very laborious task, especially if you have employees with 3-digits or more.

When you have such a task ahead, all you have to do is to create an employee list and fill it with parameters that need to be edited. We will save this file in CSV format and apply these changes to our users very quickly thanks to some powershell commands. Let’s see how we can do this with an example.

Let’s create an excel file and fill it as follows. In this example, we will edit both department and mobile phone information of our users. We will have three users as follows.


I download these users, and get the CSV file I need from Azure AD.


What I need in this list are the department and mobile phone columns, and of course the UserPrincipalName to be able to distinguish the user. You can delete other columns if you want, we don’t need them. In order to simplify the view, I delete these columns and fill the other columns as needed.


My list is all ready now. I save and close the file and change its name as “user_list.csv”. If you want to create and complete this list manually, you need to select “CSV UTF-8 (Comma Delimited)” when saving the file.


The reason we chose UTF-8 is for the Turkish characters not to be disrupted; The reason we chose Comma delimited is that the “Import-CSV” command we will use in a moment breaks these files by the “,” character by default. Therefore, we should be careful not to use the “,” character in the file.

Now we have what we need. Now, we will create a Powershell connection to Azure AD and trigger the bulk edit process. Follow the set of commands below.


# Let’s connect to Azure AD.



# Now, let’s import our CSV file.

$userlist = Import-Csv C:\Temp\user_list.csv


# Now we will execute an action

# for all our uses  in our list with a for loop.

foreach ($line in $userlist) {

$upn = $line.UserPrincipalName

$user = Get-AzureADUser -Filter “userPrincipalName eq ‘$upn'”

if ($user) {


$user | Set-AzureADUser -Department $line.department -mobile $line.mobilephone

} catch {

Write-Warning “$upn user found, but FAILED to update.”




Write-Warning “$upn not found, skipped”





here are two points you need to pay attention to here. The first is the parameters. The department is already obvious, but there are 3 parameters regarding the phone number.

-FacsimileTelephoneNumber : Fax number

-Mobile : GSM

-TelephoneNumber : Fixed line/Office phone

We will prefer the mobile parameter. To see other parameters that we can use, you can access the document of the relevant command here.

The second point we need to pay attention to is the variables we write as “$line.department”. Here, the part after “.” should match the column name in our CSV file. However, capital letters are not important.

Let’s see the result together:


You can save and run the set of commands above  as a .ps1 file or you can edit the parameters here according to your needs. You can execute this action for as many users as you want. If I need to add a final note, if there are sections in the list that you will leave blank, write “-” instead of leaving it blank and save it. Otherwise, Powershell doesn’t detect these parts and returns errors right away. I hope you enjoyed reading. Wish you all a great day 😊

Start typing and press Enter to search