AZURE AD POWER SHELL - ERROR WHEN UPDATING SPECIFIC USER ATTRIBUTES WITH CSV
Greetings everyone.
I want to update some attributes of all my users in AZURE ENTRA ID by using uploaded CSV file in AZURE CLOUD POWER SHELL.
It works fine on some attributes but I have problem with specific attributes like telephoneNumber.
When I had telephoneNumber in my script , I keep getting error and can't update.
When I catch the exception from my script it shows me the following error :
WARNING: xxx@aqw.mg user found, but FAILED to update.
Error occurred while executing SetUser
Code: Authorization_RequestDenied
Message: Insufficient privileges to complete the operation.
RequestId: b92cca4b-0343-4339-8d52-9f6a2de1071e
DateTimeStamp: Thu, 07 Nov 2024 22:43:28 GMT
HttpStatusCode: Forbidden
HttpStatusDescription: Forbidden
HttpResponseStatus: Completed
I already checked my administrator privilege and granted all privilege on my account but it doesn't work.
Here is the script i use.
Thank you in advance for helping me. Really appreciate your incoming help.
Connect-AzureAD
$CSVrecords = Import-Csv \home\present_user\test.csv -Delimiter ";"
echo $CSVrecords
foreach ($CSVrecord in $CSVrecords)
{
$upn = $CSVrecord.UserPrincipalName
$user = Get-AzureADUser -Filter "userPrincipalName eq '$upn'"
if ($user)
{
try{
$user | Set-AzureADUser -jobTitle $CSVrecord.jobTitle
$user | Set-AzureADUser -department $CSVrecord.department
$user | Set-AzureADUser -telephoneNumber $CSVrecord.telephoneNumber
}
catch
{
$FailedUsers += $upn
Write-Warning "$upn user found, but FAILED to update."
echo $_.Exception.message
}
}
else {
Write-Warning "$upn not found, skipped"
$SkippedUsers += $upn
}
}