Note for future reference:
- Open a persistant session to the exchange.
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
It will ask for your credentials.
- Import the session to your powershell:
Import-PSSession $Session - Login to Microsoft 365 admin account (to use MsolUser Cmdlet)
Connect-Msolservice (It will ask for your credentials.) - Download the contents of your Exchange Global Address list to a CSV file
get-user -resultsize unlimited |select * |export-csv c:\MS365\users.csv - 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.
Set-MsolUser
[-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>]
- 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.)