Quicktip: Adding users back to a group via Powershell

So you’ve been following my previous posts and found out that there was a big oops and those 100 groups should not have had their members removed, huh?

This script is parameter driven. Open up Powershell and launch it with name.ps1 -Gname “AName”

Read the group dump you created earlier (based off of the gname.csv output file), and adds those members back to the group.


param (
[string] $GName = $(throw "Group name is required")
)

import-module activedirectory
$Reimport=import-csv d:\Groups\Exports\$Gname.csv
foreach ($GSAM in $Reimport){
 get-adgroup $Gname|add-adgroupmember -members $GSAM.samaccountname

}

Script requires the AD Powershell modules to be installed

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s