Powershell to Update multiple AD field

Jacob Durham
Jacob Durham used Ask the Experts™
I need to create a script that search for an existing AD user using first and last name. If it finds a user with the matching name, then I'd like to set-aduser with an updated department, division, and title.

Also I'd like to set the user to report to a Supervisor if the name exists in AD.

I know this is will look something like

userbase = import-csv c:\userbase.csv

foreach-object ($user in $userbase)

if {get-aduser -identity $user.firstname+$user.lastname | set-ad-aduser -department $user.department -division $user.division -title $user.title -manager {get-aduser $user.reportsto}

else {write-host ""$user.first + $user.lastname" was not found."}

Open in new window

But I'm not sure how to parse the information from the CSV. This CSV is in the below format.

Any help it appreciated.

Business Unit               Reports To Name               First Name      Last Name      Title           DEPARTMENT
Technical Support       Hunt, Mike                      Peter              Little               Helpdesk    Technology Services
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Rated Freelancer on MS Technologies
Awarded 2018
Distinguished Expert 2018
I would use ;
Business Unit;ReportsToName;First Name;Last Name; Title; DEPARTMENT
Technical Support;    Hunt, Mike; Peter; Little;  Helpdesk; Technology Services

Open in new window

like this:
Import-Csv .\userbase.csv -Delimiter ';' | %{

    $DisplayName = $($_.'First Name' + $_.'Last Name')
        Get-AdUser -identity $DisplayName | Set-ADUser -Department $_.department -Division $_.'Business Unit' -Title $_.title -manager {get-aduser $_.ReportsToName}
        write-host ""$user.first + $user.lastname" was not found."

Open in new window

Jacob DurhamIT Support Analyst II (Lead Infrastructure Engineer)


That’s the ticket.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial