Hello Steve Brophy,
In my case, I have created one sample csv file named 2Phone.csv
with data as below:
UserPrincipalName,telephoneNumber
******@xxxxxxxxxx.onmicrosoft.com,9014xxx489
******@xxxxxxxxxx.onmicrosoft.com,123-4x6-7890
******@xxxxxxxxx.onmicrosoft.com,987-xx4-3210
******@xxxxxxxxx.onmicrosoft.com,555-1x3-4567
******@xxxxxxxxxxxxx.onmicrosoft.com,96xxxx9648
To update the BusinessPhones
property of these users, you can make use below modified PowerShell script that worked for me:
# Connect to Microsoft Graph with required permissions
Connect-MgGraph -Scopes "User-Phone.ReadWrite.All "
# Read the CSV file
$users = Import-Csv -Path "C:\temp\2Phone.csv"
# Loop through each user in the CSV and update their BusinessPhone
foreach ($user in $users) {
# Trim to remove any extra spaces
$userPrincipalName = $user.UserPrincipalName.Trim()
$BusinessPhone = $user.telephoneNumber.Trim()
# Check if the user exists in Microsoft 365
$existingUser = Get-MgUser -UserId $userPrincipalName -Property "UserPrincipalName", "BusinessPhones" -ErrorAction SilentlyContinue |
Select-Object UserPrincipalName, @{Name="BusinessPhone"; Expression={$_.BusinessPhones -join ", "}}
if ($existingUser) {
# Check if the existing BusinessPhones match the new value
if ($existingUser.BusinessPhone -eq $BusinessPhone) {
Write-Host "User '$userPrincipalName' already has BusinessPhone '$BusinessPhone'." -ForegroundColor Cyan
} else {
# Update the BusinessPhones property (as an array)
Update-MgUser -UserId $userPrincipalName -BusinessPhones @($BusinessPhone)
Write-Host "User '$userPrincipalName' updated BusinessPhone to '$BusinessPhone' successfully." -ForegroundColor Green
}
} else {
# User not found in Microsoft 365
Write-Host "User '$userPrincipalName' not found." -ForegroundColor Red
}
# Sleep to prevent rate-limiting issues
Start-Sleep -Seconds 1
}
Response:
To confirm that, I checked "SriTest" user properties where BusinessPhones
value update successfully as below:
Hope this helps!
If this answer was helpful, please click "Accept the answer" and mark Yes
, as this can be beneficial to other community members.
If you have any other questions or still running into more issues, let me know in the "comments" and I would be happy to help you.