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

Who is Participating?
Chris DentConnect With a Mentor PowerShell 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:


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.


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.