Forum Discussion
Bulk update Azure AD with user attributes from CSV
- May 08, 2020
Hello Jacob,
Your CSV has to look something like this:
UserPrincipalName;Department;TelephoneNumber
manfreddelaat@domain.nl;IT;0135113333
manfred@domain.nl;IT;0622222222Your Powershell code:
# Connect to AzureAD Connect-AzureAD # Get CSV content $CSVrecords = Import-Csv C:\Temp\Test.csv -Delimiter ";" # Create arrays for skipped and failed users $SkippedUsers = @() $FailedUsers = @() # Loop trough CSV records foreach ($CSVrecord in $CSVrecords) { $upn = $CSVrecord.UserPrincipalName $user = Get-AzureADUser -Filter "userPrincipalName eq '$upn'" if ($user) { try{ $user | Set-AzureADUser -Department $CSVrecord.Department -TelephoneNumber $CSVrecord.TelephoneNumber } catch { $FailedUsers += $upn Write-Warning "$upn user found, but FAILED to update." } } else { Write-Warning "$upn not found, skipped" $SkippedUsers += $upn } } # Array skipped users # $SkippedUsers # Array failed users # $FailedUsers
Good luck!
Kind Regards, Manfred de Laat
Hi,
PS Code turns "unsupported or invalid query filter clause specified for property userprincipalname" on my environment.
I'm trying change jobtitle and mobile attributes and edited 17th line to "Set-AzureADUser -JobTitle $CSVrecord.JobTitle -Mobile $CSVrecord.Mobile"
Do you have any suggestions ?
Regards
cevatcekli Please include the script you try to run together with your csv (example data). Also make sure you are using the latest module.
# Get My Module verion
Get-Module AzureAD | Select Version
# Get latest PSGallery version
Find-Module AzureAd | Select Version
# Update Module
Get-Module AzureAD | Update-Module
- Wim_GroffilsDec 18, 2020Brass Contributor
Having the same issue as @cevatcakli even after including the module update lines
Error:Get-AzureADUser : Error occurred while executing GetUsers Code: Request_UnsupportedQuery Message: Unsupported or invalid query filter clause specified for property 'userPrincipalName' of resource 'User'. RequestId: 5cfe785f-7d53-4fcd-b74e-b411d1b5db09 DateTimeStamp: Fri, 18 Dec 2020 09:32:43 GMT HttpStatusCode: BadRequest HttpStatusDescription: Bad Request HttpResponseStatus: Completed At line:23 char:13 + $user = Get-AzureADUser -Filter "userPrincipalName eq '$upn'" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-AzureADUser], ApiException + FullyQualifiedErrorId : Microsoft.Open.AzureAD16.Client.ApiException,Microsoft.Open.AzureAD16.PowerShell.GetUser
- Wim_GroffilsJan 29, 2021Brass Contributor
Manfred101 could you help me out too please?
- Wim_GroffilsFeb 08, 2021Brass Contributor
Nevermind I solved it!
I had to update the exo V2 module and login with MFA
And there was an issue with my source-file -> text to column in excel messed up the file, hoever this resolved that issue.
After that it worked like a charm! Thx man.