Powershell to Update multiple AD field

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
Jacob DurhamIT Support Analyst II (Lead Infrastructure Engineer)Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jacob DurhamIT Support Analyst II (Lead Infrastructure Engineer)Author Commented:
That’s the ticket.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.