Bulk update Office 365 User Details


Today, I came across a question - How to update a large batch of user attributes in Office 365.

Example - the Company, Title, Department and Office of a selection of users using information in a CSV file.

Here is an example CSV file template you could use for this. The UPN fields need to match the Office 365 login address.

 

UserPrincipalName Title Department Office Phone Mobilephone Fax Streetaddress City StateOrProvince Postalcode CountryorRegion
user1@vin-o365.in SalesManager Sales Embassy 910000001 910000002 910000003 1stfloor Bangalore KAR 560001 India
user2@vin-o365.in OperationsManager Operations Embassy 910000001 910000002 910000003 1stfloor Bangalore KAR 560001 India
user3@vin-o365.in NetworkEngineer Networking Signature 910000001 910000002 910000003 1stfloor Hyderabad AP 560002 India

 

Once you have connected to Office 365 using Powershell, you need to import the CSV file into a variable called $user_file using this command.

PS C:\scripts\>$user_file = Import-CSV c:\scripts\users.csv

Once you have this variable configured, you can run the following command to update all the users.

PS C:\scripts\>$user_file | ForEach-Object { Set-user -identity $_.Userprincipalname -title $_.Title -department $_.department -office $_.office -Phone $_.phone -Mobilephone $_.Mobilephone -Fax $_.Fax -Streetaddress $_.Streetaddress -city $_.city -StateOrProvince $_.StateOrProvince -Postalcode $_.Postalcode -countryorregion $_.CountryorRegion }

 

Comments (10)

  1. Pradeep Mishra says:

    Thanks Vinayak .

    It's really usefully command

  2. Carolyn While says:

    Hi
    The set-user command does not work it says it is an invalid cmdlet.

    1. iVinayak says:

      Connect to Exchange Online using remote PowerShell and then should be user set-user
      https://technet.microsoft.com/en-us/library/jj984289(v=exchg.160).aspx

  3. David Wilkinson says:

    When i run the command it says WARNING: The command completed successfully but no settings of user_name have been modified

    So it looks like it runs but obviously doesnt make any changes to the users. I am running the following command

    $user_file | ForEach-Object {Set-user -identity $_.login_name -title $_.Title -Phone $_.phone -Streetaddress $_.Streetaddress -city $_.city -Postalcode $_.Postalcode}

    1. Cat says:

      I noticed that for each try, I need to import a new CSV or start the powershell session over. Once you import a CSV, it keeps trying to use the same one unless you import another one with a different name.

  4. Mohamed Attia says:

    Thanks a lot

  5. Farooque says:

    Set-User : The term 'Set-User' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
    spelling of the name, or if a path was included, verify that the path is correct and try again.
    At line:1 char:18
    + ForEach-Object {Set-User -Identity $_.username -Title $_title -Mobil ...
    + ~~~~~~~~
    + CategoryInfo : ObjectNotFound: (Set-User:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    1. JithinK says:

      its not set-user; it is "Set-MsolUser

  6. surtafel says:

    Is it possible to add company attributes here?how?

  7. Andrew.TN says:

    Thanks this helped me finish off a script I was working on that allows me to update all user's except a select few UserPrincipalName to their WindowsEmailAddress.

Skip to main content