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
Jan 17 2023 01:42 AM
Jan 17 2023 01:43 AM
Nov 10 2023 01:01 PM
Nov 15 2023 03:27 AM
Hi, You have to use the ExtensionProperty to set the null value or clear the property with Set-AzureADUser cmdlet.
$properties = [Collections.Generic.Dictionary[[String],[String]]]::new()
$properties.Add("Mobile", [NullString]::Value)
Set-AzureADUser -ObjectId "email address removed for privacy reasons" -ExtensionProperty $properties
# Refer to the below post for more details.
# https://morgantechspace.com/2022/03/update-bulk-azure-ad-user-attributes-using-powershell.html
Check this post for more details: Remove or Clear Property or Set Null value using Set-AzureADUser cmdlet
Nov 21 2023 01:11 PM
Dec 14 2023 12:18 PM - edited Dec 14 2023 10:58 PM
Similarly for updating the office location of users in Azure AD in bulk I've tried updating the above script as mentioned below (In CSV file taken values with columns userPrincipalName and officeLocation)
foreach ($CSVrecord in $CSVrecords) {
$upn = $CSVrecord.userPrincipalName
$user = Get-AzureADUser -Filter "userPrincipalName eq '$upn'"
if ($user) {
try{
$user | Set-AzureADUser -officeLocation $CSVrecord.officeLocation
} catch {
$FailedUsers += $upn
Write-Warning "$upn user found, but FAILED to update."
}
}
else {
Write-Warning "$upn not found, skipped"
$SkippedUsers += $upn
}
}
But all the users were getting skipped instead of office location being populated for the users, as per the csv file with warning:
WARNING: user found, but FAILED to update.
Requesting your help
Dec 14 2023 12:29 PM
Dec 17 2023 05:43 AM
Jan 15 2024 09:28 PM
@Manfred101 Could you let me know the performance of this code, if I am trying to update 5000 records, typically how much time will this take?