PowerShell: ADMemebers of multiple ADGroups

So you need to provide a list of AD groups and the AD members of those groups. The AD group names all start with FIN_.

Our friends over at Quest have written a great PowerShell snapin that can help us with this. The Snapin is Quest.ActiveRoles.ADManagement.

You can download it here: http://www.quest.com/powershell/activeroles-server.aspx

Here is the code that will give you the output you need:

foreach($adgroup in get-qadgroup|where-object{$_.name -match "FIN_"}) {get-qadgroupmember $adgroup.name | Format-Table -property $adgroup.name, name}

We are using a foreach loop so that we can run through all the groups and then pull the members. Main reason we do it this way is because we need to maintain the groupname for the output in the table.

So we stick the groupname in $adgroup, we match the groups with the where-object{$_.name -match "FIN_" command. Now that we have the groups, we use the $adgroup.name to pull the members.

There might be a better, shorter, and, or, more efficient way to do this, but this works perfect.

Advertisements
Posted in Uncategorized

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

Archives
%d bloggers like this: