Sign up for Office 365
Learn more about Office 365
I'm trying to update the Company, Department, and Office fields for all of my Office 365 users. I was able to do this for all of my external contacts but can't seem to get it to work for actual 365 users (Mailboxes as opposed to Contacts).
I have a CSV that has several fields in it. Office, Department, Title, Company, as well as Full_Name, Email_Address
I want it to read the file and update(Overwrite) the data currently on their account.
I start with the command:
$users = Import-CSV c:\scripts\users.csv
Then I try and get it to import by using:
$users | ForEach {Set-mailuser $_.EMAIL_ADDRESS -Company $_.Company -Title $_.Title -Department $_.Department -Office ("Office "+($_.Office))}
I've also tried:
$users | ForEach {Set-MSOLUSER $_.EMAIL_ADDRESS -Company $_.Company -Title $_.Title -Department $_.Department -Office ("Office "+($_.Office))}
Neither of these are working. I think the Set-MSOLUSER will be the key, but I can't seem to get the syntax working correctly.
I updated my external contacts using almost the exact same command successfully.
$users | ForEach {Set-contacts $_.EMAIL_ADDRESS -Company $_.Company -Title $_.Title -Department $_.Department -Office ("Office "+($_.Office))}
Any advise would be greatly appreciated.
Try this
$users | ForEach {Set-user $_.EMAIL_ADDRESS -Company $_.Company -Title $_.Title -Department $_.Department -Office ("Office "+($_.Office))}
Regards,
Alan Byrne
Cogmotive Reports
Office 365 Reports
1 out of 1 people found this post helpful.
Firstly, I don't think you can set the Company attribute using Set-MSOLUser. So for the purposes of troubleshooting, can you try just setting the Title, department and office?
Secondly, I think you'll need to add the -UserPrincipalName switch to the set-msoluser command
$users | ForEach {Set-MSOLUSER -UserPrincipalName $_.EMAIL_ADDRESS -Company $_.Company -Title $_.Title -Department $_.Department -Office ("Office "+($_.Office))}
Thanks for the reply.
Ok. So I made the suggestion you mentioned and removed the attempt to update the Company field, and only update Title, Department, and Office as well as use the -userPrincipalName value and that seems to have worked.
Now how can I update the Company field? It's fine if I have to do that update apart from the others just as long as I can do it on a csv to avoid having to manually update the value from the GUI. I can create a csv with just the Email_Address field and Company or would I be able to just reuse the other file and it disregard the undefined columns?
Thank you for your help. That last command, did exactly what I needed.
Glad to hear it worked, I learned something as well!
I've written up a short blog post about it, hopefully the next person who needs this information finds it useful:
www.cogmotive.com/.../update-office-365-user-details-from-a-csv-file