Forum Discussion
Automated PS1 script to update O365 Contacts
Hi Tech Community,
I was tasked to automate the update of O365 Contacts from the automated export of details from one of our systems which holds the mobile,telephone #. The script below used is working but I don't know how to automate it as my GA account has MFA activate hence cannot use app password on the PS1.
Just wanted to know as well which account has been updated or not as the info from the csv file contains user that is not on O365 as well.
Error Encountered:
Set-MsolUser : User Not Found. User: .
At line:1 char:21
+ ... | foreach {Set-MsolUser -UserPrincipalName $_.'Email Address' -Mobil ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [Set-MsolUser], MicrosoftOnlineException
+ FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.UserNotFoundException,Microsoft.Online.Administration.Automation.SetUser
Set-MsolUser : You must provide a required property: Parameter name: ObjectId
At line:1 char:21
+ ... | foreach {Set-MsolUser -UserPrincipalName $_.'Email Address' -Mobil ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [Set-MsolUser], MicrosoftOnlineException
+ FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.RequiredPropertyNotSetException,Microsoft.Online.Administration.Automation.SetUser
Script Used:
Connect-MsolService -Credential
$csvPath =$(Get-ChildItem -path 'C:\Export' | ? { ($_.Extension -eq '.csv') -and ($_.Name -match 'Export_Contact_Info')} | Sort-Object CreationTime -Descending)[0]
$csvData = Get-Content -Path $csvPath.fullname | Select-Object -Skip 2 | Out-String | ConvertFrom-Csv
$csvData | foreach {Set-MsolUser -UserPrincipalName $_.'Email Address' -MobilePhone $_.'Mobile Formated' -PhoneNumber $_.'DID formated'}
Best Regards,
Mark
6 Replies
The error message has nothing to do with authentication, most likely the identifier that you are using ("Email address") doesn't return a match. Anyway, if you want to automate the process, either use an account that has MFA disabled, or configure bypass (known location/trusted IPs is my preferred solution for bypassing MFA).
- Mark Louie DiazCopper Contributor
VasilMichev Hi,
Would you share me more about the trusted/known IP location to bypass MFA?
Best Regards,
Mark