This is what I've used to bulk upload, using the Access Token
#Access token required to update the record
$accessToken = "API Access Key here"
$filename = '\usersdata.txt'
# Loop a csv here with the userID and mobile numbers
$records = import-csv $filename
foreach ($record in $records){
$user = $record.USER_ID
$mobile = $record.PHONE
$uri = "https://graph.microsoft.com/beta/users/$user@<domain>/authentication/phoneMethods"
$body = @"
{
"phoneType": "mobile",
"phoneNumber": "$mobile"
}
"@
if ($mobile -match '((\+[0-9]{1,3}[ ])[0-9]{4,})'){ # Check number is in correct format
write-host "Checking Number: $user, $mobile"
if ((Invoke-RestMethod -Method Get -Uri $uri -Headers @{"Authorization"="Bearer $accessToken"}).value.phoneType -ne 'mobile') {
write-host "Adding Number: $user, $mobile" -foregroundcolor green
try {
Invoke-RestMethod -Method Post -Uri $uri -Headers @{"Authorization"="Bearer $accessToken"} -Body $body
$setMobile = (Invoke-RestMethod -Method Get -Uri $uri -Headers @{"Authorization"="Bearer $accessToken"}).value.phoneNumber
if ($setMobile -ne $mobile){
write-host "$user has their phone listed as $mobile, but it is $setMobile in Azure" -foregroundcolor red
}
}
catch {
Write-Host "Something wrong with the phone number for $user, $mobile" -foregroundcolor red
}
}
else{
$existingMobile = (Invoke-RestMethod -Method Get -Uri $uri -Headers @{"Authorization"="Bearer $accessToken"}).value.phoneNumber
if ($existingMobile -ne $mobile){
write-host "Skipping: $user, $mobile as $existingMobile already exists but don't match" -ForegroundColor yellow
}
else {
write-host "Skipping: $user, $mobile as $existingMobile already exists"
}
}
}
else{
$existingMobile = (Invoke-RestMethod -Method Get -Uri $uri -Headers @{"Authorization"="Bearer $accessToken"}).value.phoneNumber
write-host "Skipping: $user, $mobile Unknown CountryCode or invalid number" -foregroundcolor Red
}
}