Forum Discussion

Mark Louie Diaz's avatar
Mark Louie Diaz
Copper Contributor
Aug 28, 2019

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

Resources