Powershell to Update multiple AD field

Jacob Durham
Jacob Durham used Ask the Experts™
on
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
Comment
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
Commented:
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')
    try{
        Get-AdUser -identity $DisplayName | Set-ADUser -Department $_.department -Division $_.'Business Unit' -Title $_.title -manager {get-aduser $_.ReportsToName}
    }
    catch{
        write-host ""$user.first + $user.lastname" was not found."
    }
}

Open in new window

Jacob DurhamIT Support Analyst II (Lead Infrastructure Engineer)

Author

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