AZURE AD POWER SHELL - ERROR WHEN UPDATING SPECIFIC USER ATTRIBUTES WITH CSV

Faniry RAVELOMANANTSOA 0 Reputation points
2024-11-07T23:09:01.98+00:00

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

}
}


PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,592 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
22,103 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.