Small script to list a users distribution group memberships in Exchange 2007 and 2010

I have created a small script to list the current group membership for a specific user. Save the code to a ps1 file and execute.

$User = read-host -Prompt "Enter Username"
"User " + $User + " is a member of the following groups:"

ForEach ($Group in Get-DistributionGroup)
{
   ForEach ($Member in Get-DistributionGroupMember -identity $Group | Where { $_.Name –eq $User })
   {
      $Group.name
   }
}

For example, I saved the file as c:\DGMemebrship.ps1 and executed it using the following command:
./DGMemebrship.ps1

DGMembership

Advertisements

7 Responses to Small script to list a users distribution group memberships in Exchange 2007 and 2010

  1. Jon Reeves says:

    Hi,

    Thanks for posting this, but there does appear to be a small mistake:

    -identity $Group

    Should be changed to

    -identity $Group.Name

    At least on Exchange 2010 I needed to change this, might be a difference between 2007 and 2010

    Cheers
    Jon

  2. PHILH says:

    worked a treat for me, also showed me a had a couple of corrupted lists due to invalid aliases – thanks

  3. Shawn Thompson says:

    I’m getting the following when I try to run the script…

    The string starting:
    At H:\Documents\get-dist-group-membership.ps1:6 char:89
    + ForEach ($Member in Get-DistributionGroupMember -identity $Group | Where { $_.Name â? <<<< "eq $User })
    is missing the terminator: ".
    At H:\Documents\get-dist-group-membership.ps1:11 char:1
    + <<<<
    + CategoryInfo : ParserError: (eq $User })
    …name
    }
    }
    :String) [], ParseException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

    Any ideas? Thanks much.

    • Martin Sundström says:

      I Shawn and thanks for Reading! It does look like the syntax is wrong, are you sure that you got the copy/editing right? The characters â? <<<< " should only be a dash –
      Go through the code and see if you can find it, let me know if ou can't get it to work.

  4. Trey says:

    Hello,

    Where would I be able to place a -ResultSize unlimited parameter?

  5. Thanks a lot!!! This works, but like Jon Reeves mentioned, I had to edit the -identity $Group to -identity $Group.NAME

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

%d bloggers like this: