PowerShell - Add Users to Group from CSV

16. October 2011 14:56

I needed to add users to groups by PowerShell and was having trouble finding examples how to do it.  Here is how I figured it out.

First, you need a CSV of the users's logon names.  My list came from the CSV from:

Get-DistributionGroupMember -Identity 'Some List' | Export-Csv 'list.csv'

The list generated above consisted of alot of fields.  The only one I am interested in for this use is "Alias".  Once I had the list generated from my old AD, I then ran:

Import-Csv 'list.csv' | ForEach-Object { Add-ADGroupMember -Identity "Some New Group Name" -Members $_.Alias }

Remember the script above needs to be a single line.  I had to break it apart so it will fit in the blog format.  It worked like a charm.

About Jim Bouse

I grew up with computers being a part of my life.  I set up my first 'network' by 15 (in 1997) and have been exploring innovative ways to make the lives easier for everyday people using tools readibly available.

 

I now work for Texas A&M University as a Senior Systems Administrator designing and maintaining a GIS system that is used by thousands of users daily.