0

PowerShell - Add Users to Group from CSV

by Jim 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.

Tags: , , , ,

PowerShell

Powered by BlogEngine.NET 2.5.0.6
Original Design by Laptop Geek, Adapted by onesoft