Saturday, May 17, 2008

Enumerate all Email groups a user is a member of

Quick script to show all email distribution groups that a particular user is a member of:


#
# Cobbled together by Gnawgnu
# 5/17/08

#get the identity of the user by alias
$Username = (get-user gnawgnu).Identity

#search all groups for that user
$groups = get-group -Filter {Members -eq $username}

#display all groups that have an email address
#defined that's longer than 0 characters
$groups | Where-Object {$_.WindowsEmailAddress.Length -ne 0}

2 comments:

Unknown said...

Thanks man !

This is just what I've been looking for.

I'm now a regular visitor to your blog for any useful Powershell script.

Cheers,

Albert

Anonymous said...

Another alternative:

get-group | where-object {$_.Members -eq (get-user alias).Identity}