We help IT Professionals succeed at work.

Powershell to update users in ADUC

gd6627
gd6627 asked
on
87 Views
Last Modified: 2018-09-12
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
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018

Commented:
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

Author

Commented:
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
CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
thank you
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.