Powershell script to update managed by field in AD

I am looking to create a powershell script that will pull from an excel sheet the name of the DL and than update the managed by field in AD as well enable the manager to update the dl.  Is there a way to do this in powershell or vb
Distribution List	Owner
test	bobbyj

Open in new window

LVL 3
brianm71Asked:
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.

Chris DentPowerShell DeveloperCommented:

I like PowerShell a lot, but... can I convince you to change that Excel file for a CSV? Because Excel adds unnecessary pain.

If you do have a CSV... I'd suggest you grab these as they will simplify the task even further:

http://www.quest.com/activeroles-server/arms.aspx

With that we can do...

Import-CVS "YourCSVFile.csv" | %{
  Set-QADGroup $_."Distribution List" -ManagedBy "$($Env:UserDomain)\$($_.Owner)"
}

% is an alias for ForEach-Object, it loops us through the contents of the CSV file (which is imported into an Object in PowerShell).

"Distribution List" is in quotes above because of the space, it just references the field in your CSV, it's not something that needs altering.

$Env:UserDomain will fill itself in with your current domain name, combined with Owner read from the spreadsheet.

HTH

Chris
0

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
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
Scripting Languages

From novice to tech pro — start learning today.