Avatar of gd6627
gd6627
Flag for United States of America asked on

Powershell to update users in ADUC

I need to run an update for all users in the user aduc with PowerShell to update the following fields.
The PowerShell script needs to read the information from a csv file that will then go to ad and update the information

I need to key off of the user samaccountname and update the following :
Department
Title
Manager
Telephone
Office
Address
city
state
zipcode
PowershellActive Directory

Avatar of undefined
Last Comment
gd6627

8/22/2022 - Mon
oBdA

Try this; the csv should have the column names you listed (plus SamAccountName, obviously).
The "Manager" column should contain the respective manager's SamAccountName.
$managers = @{}
Import-Csv -Path C:\Temp\users.csv | ForEach-Object {
	"Processing $($_.SamAccountName) ..." | Write-Host
	If (-not $managers.ContainsKey($_.Manager)) {
		"  Caching manager '$($_.Manager)' ..." | Write-Host
		$managers[$_.Manager] = (Get-ADUser -Identity $_.Manager).DistinguishedName
	}
	$splat = @{
		Department = $_.Department
		Title = $_.Title
		Manager = $managers[$_.Manager]
		OfficePhone = $_.Telephone
		Office = $_.Office
		StreetAddress = $_.Address
		City = $_.City
		State = $_.State
		PostalCode = $_.ZipCode
	}
	Set-ADUser -Identity $_.SamAccountName @splat
}

Open in new window

gd6627

ASKER
Hi Thanks can you explain so I understand what your script is actually doing , from what I tried to interpret you r importing the csv but the if statement for manager I need to understand for my own knowledge of how it works

Thank you
ASKER CERTIFIED SOLUTION
oBdA

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
gd6627

ASKER
thank you
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck