May 08 2020 08:22 AM
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 here and if I have not given enough information, please let me know. I tried using Set-AzureADUser piping records using a foreach statement from a csv that I imported, but it was throwing up errors.
Thanks!
Jacob
May 08 2020 11:28 AM - edited May 08 2020 11:41 AM
SolutionHello Jacob,
Your CSV has to look something like this:
UserPrincipalName;Department;TelephoneNumber
manfreddelaat@domain.nl;IT;0135113333
manfred@domain.nl;IT;0622222222
Your 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
May 08 2020 03:59 PM
May 18 2020 12:43 PM
@jebujohnYou're welcome! Take care!
May 21 2020 09:13 PM
Dear @Manfred101,
In the same scenario if I wanted to add -EmployeeID from a csv, would it be possible to use a similar script. -EmployeeID seems to be an azureaduserextension.
Jacob
May 22 2020 02:48 AM
@Jacob John Just add this line below line 17:
$user | Set-AzureADUserExtension -ExtensionName "employeeId" -ExtensionValue $CSVrecord.employeeId
And make sure you add the "employeeId" records are present in your CSV file.
Good Luck!
Grtz, Manfred de Laat
May 22 2020 03:15 AM
Jul 10 2020 12:42 AM
Thanks for sharing script here to update user details. But, I would draw your attention that script is working with only one user details, when I do it with more than one row, its giving the following warning and finally users details not updated.
Here is the CSV file content:
Can you help me to resolve this issue?
Aug 03 2020 12:45 PM
@Manfred101 Thank you for the script, i have two questions,
We update the AD attributes based on the EmployeeId, can the script be run by the EmployeeID instead of the upn, if yes, please how?
is the powershell script handle about 5k users or it's limited to a number of users only?
thank you in advance.
Daniel.
Sep 09 2020 04:32 AM
Hi... thanks fr your script
its not adding for guest user
anything in need to do for guest user
Sep 09 2020 05:20 AM
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
Oct 23 2020 04:45 AM
@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.
Nov 25 2020 06:46 AM
I am getting the same issue - did you get it working?
Nov 25 2020 02:29 PM
@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
Nov 26 2020 08:44 AM
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 ";")
Nov 26 2020 04:53 PM
I'm having trouble bulk updating the Manager field. Would I be able to use this script to bulk update the managers property for the individual users?
Thanks-
Nov 27 2020 12:34 AM - edited Nov 27 2020 12:45 AM
@wllrkn Thanks for your feedback - I made the changes.
I also noticed spaces in my CSV file and i also removed fields not needed.
Cheers buddy
Nov 27 2020 12:50 AM
maybe - i just managed to do job title and department
I changed the highlighted line below so maybe you can add -Manager $CSVrecord.Manager
Make sure there are no spaces in your CVS.
$user = Get-AzureADUser -Filter "userPrincipalName eq '$upn'"
if ($user) {
try{
$user | Set-AzureADUser -Department $CSVrecord.Department -jobTitle $CSVrecord.jobTitle
Nov 27 2020 02:50 AM
can you please advice how i can change the manager in bulk for all employees?
there is just one manager account and 130 employees, all of them need to have this manager in Azure AD in order for a flow to work.
thanks
Nov 27 2020 03:19 AM
May 08 2020 11:28 AM - edited May 08 2020 11:41 AM
SolutionHello Jacob,
Your CSV has to look something like this:
UserPrincipalName;Department;TelephoneNumber
manfreddelaat@domain.nl;IT;0135113333
manfred@domain.nl;IT;0622222222
Your 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