Forum Discussion
Bulk update Azure AD from Powershell - FAILED to update
Hi, Jason.
We'd need to know what the real error thrown by Set-AzureADUser is rather than the generic error you're reporting from the catch block to have any idea of where to start.
As an important side note, the AzureAD modules are now deprecated (along with others) and you should be moving to the replacemenet Microsoft.Graph.* modules.
- Important update: Azure AD Graph API retirement - Microsoft Community Hub
- Migrate from Azure Active Directory (Azure AD) Graph to Microsoft Graph - Microsoft Graph | Microsoft Learn
Cheers,
Lain
I would love to know the error but it just isnt giving one.
ill look into Microsoft Graph, Thanks
- LainRobertsonApr 26, 2024Silver Contributor
Here's your script with the try...catch block removed - perhaps save it as a different name while you diagnose the root issue.
If you run this version, you should see the real error(s) being listed.
If your CSV is large, consider reducing it in size for this diagnostic-only version of the script, as there's no value in having a thousand of the same error popping up.
$CSVrecords = Import-Csv C:\Temp\Test.csv -Delimiter "," $SkippedUsers = @() $FailedUsers = @() foreach ($CSVrecord in $CSVrecords) { $upn = $CSVrecord.UserPrincipalName $user = Get-AzureADUser -Filter "userPrincipalName eq '$upn'" if ($user) { $user | Set-AzureADUser -jobTitle $CSVrecord.jobTitle -department $CSVrecord.department -officeLocation $CSVrecord.officeLocation -streetAddress $CSVrecord.streetAddress -city $CSVrecord.city -state $CSVrecord.state -postalCode $CSVrecord.postalCode -telephoneNumber $CSVrecord.telephoneNumber -mobile $CSVrecord.mobile } else { Write-Warning "$upn not found, skipped" $SkippedUsers += $upn } }Cheers,
Lain