Forum Discussion
TKMB-IT
Aug 02, 2020Copper Contributor
Bulk Update with Company Name in Azure AD
Hello Community, I'm trying to update users in bulk for the attribute of Azure AD which is called "Company Name" but when I tried to export all of the users in CSV, unfortunately, there was no su...
VasilMichev
Aug 03, 2020MVP
Well how are you exporting it, the code above has nothing that relates to exporting to CSV file. I can see the CompanyName attribute just fine via the Get-AzureADUser cmdlet...
Angelio
Mar 09, 2022Copper Contributor
VasilMichev What am I doing wrong here?
I need to update office and company...
# Connect to AzureAD
Connect-AzureAD
# Get CSV content
$CSVrecords = Import-Csv C:\PSscripts\office.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{
Set-AzureADUser -ObjectId $($_.ObjectId) -PhysicalDeliveryOfficeName $CSVrecord.PhysicalDeliveryOfficeName -CompanyName $CSVrecord.CompanyName
} 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
---------
CVS looks like this.
But i'm getting the error...
Warning: xxxx user found but failed to update.
If i do not use OBjectID, it throws an error...
cmdlet Set-AzureADUser at command pipeline position 1
Supply values for the following parameters:
ObjectId:
Appreciate your help.
Thanks