EMS Script
I recently had to put a script together that would get a set of distribution groups and its members. The built in commands of get- distributiongroup will only dump the group name and its properties, the command of get-distributionmember will only dump the members.
The following script is take in an OU path and print out the GroupName and its members.
## This script will get distrobution Groups and print out
## the Group Name and Members alias and Primary smtp address
##
## Example
## groupName: Group1
## groupsMembers:
##
## alias PrimarySmtpAddress
## —- ——————
## User.Alias USER@primarysmtpaddress
$OU=”InputHere”
##input OU path above
foreach($group in Get-DistributionGroup -OrganizationalUnit $Ou)
{
write-output “GroupName:$group “
Write-output “GroupsMembers:”
Get-DistributionGroupMember $group ft alias,primarysmtpaddress
write-output ‘ ‘
}

![[Google]]( http://www.exchange-genie.com/wp-content/plugins/easy-adsenser/google-light.gif)
June 30th, 2008 at 5:17 am
I like your blog
Here’s another way to get all members of the groups in one table:
foreach($group in Get-DistributionGroup -OrganizationalUnit $Ou){
Get-DistributionGroupMember $group | select @{n=”DistributionGroup”;e={$group.name}},@{n=”MemberName”;e={$_.name}},alias,primarysmtpaddress
}
—
Shay Levy
$cript Fanatic
http://scriptolog.blogspot.com