Link to home
Start Free TrialLog in
Avatar of gd6627
gd6627Flag 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
Avatar of oBdA
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

Avatar of 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
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gd6627

ASKER

thank you