Bulk Update User information in Microsoft 365 Exchange using powershell.

31 May

Note for future reference:

  1. Open a persistant session to the exchange.
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $UserCredential -Authentication Basic -AllowRedirection

It will ask for your credentials.

  1. Import the session to your powershell:
    Import-PSSession $Session
  2. Login to Microsoft 365 admin account (to use MsolUser Cmdlet)
    Connect-Msolservice (It will ask for your credentials.)
  3. Download the contents of your Exchange Global Address list to a CSV file
    get-user -resultsize unlimited |select * |export-csv c:\MS365\users.csv
  4. Remove unneccessry columns and edit what you need. (dont delete the columns named UserPrincipalName and Identity we need to use them later.)
    In this usecase I will use Set-MsolUser module, which supports the following options.

[-ImmutableId ]
[-ObjectId ]
[-UserPrincipalName ]
[-BlockCredential ]
[-City ]
[-Country ]
[-Department ]
[-DisplayName ]
[-Fax ]
[-FirstName ]
[-LastName ]
[-LastPasswordChangeTimestamp ]
[-MobilePhone ]
[-Office ]
[-PasswordNeverExpires ]
[-PhoneNumber ]
[-PostalCode ]
[-PreferredDataLocation ]
[-PreferredLanguage ]
[-SoftDeletionTimestamp ]
[-State ]
[-StreetAddress ]
[-StrongPasswordRequired ]
[-Title ]
[-UsageLocation ]
[-AlternateEmailAddresses ]
[-StrongAuthenticationMethods ]
[-AlternateMobilePhones ]
[-StrongAuthenticationRequirements ]
[-StsRefreshTokensValidFrom ]
[-UserType ]
[-TenantId <Guid>]

  1. After updating the CSV, import the updated csv to powershell and execute the changes.

in the below script, header names referenced with a hyphon are the names we used in our sheet. header names referenced with $_. are the ones that the exchange is expecting from us. To make it simpler I used the same names as exchange in my sheet.

to map a field to a field in exchange we use this syntax : – $_.

Import-Csv C:\M365\users.csv | foreach{Set-MsolUser -UserPrincipalName $_.UserPrincipalName -DisplayName $_.DisplayName -FirstName $_.FirstName -LastName $_.LastName -City $_.City -StreetAddress $_.StreetAddress -Department $_.Department -Country $_.Country -MobilePhone $_.MobilePhone}

supported field names are shown in step 5.

In this script we are using UserPrincipalName as the main reference.

After running this script it takes a few minutes to be able to see your changes in the Exchange Admin portal.

(This note is based on what I did today. I have very little understanding of powershell, if you are going to try these steps please do your research first.)

Leave a comment

Posted by on May 31, 2021 in Uncategorized


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: