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 # $FailedUsersGood luck!
Kind Regards, Manfred de Laat
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
Manfred101 could you help me out too please?
- Wim_GroffilsFeb 08, 2021Brass Contributor
Nevermind I solved it!
I had to https://docs.microsoft.com/en-us/powershell/exchange/exchange-online-powershell-v2?view=exchange-ps#install-and-maintain-the-exo-v2-module and https://docs.microsoft.com/en-us/powershell/exchange/connect-to-exchange-online-powershell?view=exchange-ps#:~:text=%20Connect%20to%20Exchange%20Online%20PowerShell%20using%20modern,need%20to%20run%20uses%20the%20following...%20More
And there was an issue with my source-file -> text to column in excel messed up the file, hoever https://stackoverflow.com/questions/49642320/reversing-text-to-columns-in-excel-calc resolved that issue.
After that it worked like a charm! Thx man.