Forum Discussion
jebujohn
May 08, 2020Copper Contributor
Bulk update Azure AD with user attributes from CSV
I am looking for a way to update user attributes (OfficePhone and Department) for about 500 users from a CSV to AzureAD using a powershell. Does anyone know of a script that I could use? I am new her...
- 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
Manfred101
Sep 09, 2020Iron Contributor
The UPN of a guest users is a bit different from normal users. Make sure you can map them from your csv file. Should look like this: m.delaat_mycompany.nl#EXT#@yourTenantname.onmicrosoft.com
Good luck!
Manfred de Laat
DK_Belgrade
Oct 23, 2020Copper Contributor
Manfred101Hi, i am traying to make bulk settings for guest users. But i receive the following error message
Get-AzureADUser : Error occurred while executing GetUsers
Code: Request_UnsupportedQuery
Message: Unsupported or invalid query filter clause specified for property 'userPrincipalName' of resource 'User'.
I checked a script many times and everything seems good, also i changed proper UPN for "Guest user" in my CSV file.
Thanks in advanced for help.
- jpcaidNov 25, 2020Copper Contributor
I am getting the same issue - did you get it working?
- wllrknNov 26, 2020Copper Contributor
You need to change line 5 to
$CSVrecords = Import-Csv C:\Temp\Test.csv
Then the script should work. (You do not need to delimit the ";")
- LukeWeldenMay 11, 2021Copper Contributor
wllrkn Thanks bunch, removing this fixed the issue for me :).
- Manfred101Nov 25, 2020Iron Contributor
jpcaid and DK_Belgrade , I am very busy at the moment guys. But I will have a look at this in the next couple of days. Grtz, Manfred de Laat