Changing User manager field in ADUC

I like to run a Powershell script that will go thru a csv file and change who the user manager is  .
so for example if the csv has all the users in the marketing department I would want to change who they report to
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.

If it's a csv with a header line, and (at least) one column "SamAccountName", and the Manager is supposed to be the same for all users, it would be
Import-Csv | ForEach-Object {Set-ADUser -Identity $_.SamAccountName -Manager "<Manager's SamAccountName>"}

Open in new window

If it's a csv with a header line, and (at least) two columns, "SamAccountName" and "Manager" (with the manager's SamAccountName), it would be
Import-Csv | ForEach-Object {Set-ADUser -Identity $_.SamAccountName -Manager $_.Manager}

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
gd6627Author Commented:
So after the import-csv I define the location of the csv file correct , then if I use the first script the colum of the csv file identifying the user will be for example _Mysamaccount as the header the manager will be in the parentheses correct ?

then in the second script I would have a columm for user and a columm for managers  correct?
For the first script, the csv needs to look like that (Colx are optional columns, PS doesn't care - SamAccountName is mandatory)
Col0, SamAccountName, Col1, Col2, ...
Data0, UserA, Data1, Data2, ...

Open in new window

The manager's SamAccountName must be inside the double quotes.

For the second script, the csv needs to look like that (Colx are optional columns, PS doesn't care - SamAccountName and Manager are mandatory)
Col0, SamAccountName, Col1, Manager, Col2, ...
Data0, UserA, Data1, ManagerA, Data2, ...

Open in new window

In either csv, the cells can/may be enclosed in double quotes; they must be enclosed if the cell data contains the field delimiter.
gd6627Author Commented:
gd6627Author Commented:
thank you
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.