Set Department

Hi Everyone.
I am working on a PowerShell script to update user's department field. I have a CSV file that has the username and department field. i want to set the department of the users in the CSV based on what is in the CSV.  the script below is not working for me. any idea ?

Import-Module ActiveDirectory
$Users = Import-csv c:\Users.csv
foreach($User in $Users){
Set-ADUser $User.username -Department $User.Department
Debrata 1Asked:
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.

Should work just fine. Do you get error messages, and if so, which ones?
Does your csv have a header line with a column named "UserName" and one named "Department"?
Is the UserName the user's SamAccountName attribute?
Do you have enough permissions to change the department? In particular: are you running this in an elevated console?

Experts Exchange Solution brought to you by ConnectWise

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
Debrata 1Author Commented:
Thanks! it's working. I just had to change the column names as you pointed out.
Question answered.
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.

All Courses

From novice to tech pro — start learning today.