'Azure AD Updating Bulk users from CSV
I am new to this so please apologise if I missed some information.
I have the following situation:
I have a employee list in CSV and I need to update existing users in my tenent through powershell. I tried some skripts I found online but non of them I could get working. I can connect to the tenent and import the csv but nothing more.
I need to update the following:
fax, office, streetadress, city, postalcode, department, title, officephone, mobilephone and mail
Can someone give me a template or something similar? I would really appreciate some help.
Solution 1:[1]
If your csv file is listed with a distinguishable object e.g. Active Directory User sAMaccount's and its correlating data 'fax, office, streetadress, city, postalcode, department, title, officephone, mobilephone and mail'
High Level Steps To Update Active Directory User Properties
- Import Active Directory Module
- Import CSV File containing data to be matched and updated
- Run Get-ADUser cmdlet to get the object to be updated
- Run Set-ADUser cmdlet to update the property
Example Script To Update AD User From CSV File
#Import Active Directory module
Import-Module ActiveDirectory
#Import CSV File to set variable for the user’s logon name + update data + delimiter
$Users = Import-CSV -Delimiter ";" -Path "c:\psscripts\users.csv"
#Using your code to filter AD Sam Accounts listed CSVData is listed with the information you wish to update
Foreach($user in $users){
#Using your code to filter AD Sam Accounts Based on column samaccountname in the csv file
Get-ADUser -Filter "SamAccountName -eq '$($user.samaccountname)'" | Set-ADUSer `
-fax $($User.Fax) `
-office $($User.Office) `
-StreetAddress $($User.StreetAddress) `
-city $($User.City) `
-postalcode $($User.PostCode) `
-title $($User.Title)`
-department $($User.Department) `
-officephone $($User.Officephone) `
-mobilephone $($User.Mobilephone) `
-mail ($User.Mail)
}
Solution 2:[2]
The below post shares the PowerShell script to modify bulk user attributes for multiple user accounts in a simple way by importing user details from a CSV file.
https://morgantechspace.com/2022/03/update-bulk-azure-ad-user-attributes-using-powershell.html
This script helps to update bulk user attributes as hashtable in a single command (Set-AzureADUser).
#Hashtable to keep multiple attribute values
$AttributesToUpdate = @{}
$AttributesToUpdate["JobTitle"] = "Sales Manager"
$AttributesToUpdate["Department"] = "Sales"
# Set required user attributes.
# Need to prefix the variable AttributesToUpdate with @ symbol instead of $ to pass hashtable as parameters (ex: @AttributesToUpdate).
Set-AzureADUser -ObjectId "[email protected]" @AttributesToUpdate
# Refer to the below post for more details.
# https://morgantechspace.com/2022/03/update-bulk-azure-ad-user-attributes-using-powershell.html
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | NeoTheNerd |
Solution 2 | Kevin M |