Created
November 15, 2012 12:52
-
-
Save wadtech/4078495 to your computer and use it in GitHub Desktop.
Script to find distribution group memberships of a user.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# List-DistributionGroups.ps1 | |
# Peter Mellett 2012 | |
# | |
# Find all distribution groups of a user and list them to the console | |
# | |
# Example: | |
# .\List-DistributionGroups.ps1 [email protected] | |
# | |
# Name | |
# ==== | |
# Marketing | |
# Managers | |
# | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory=$True,Position=1)] | |
[string]$email | |
) | |
if (Test-Path 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1') { | |
. 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1' | |
Connect-ExchangeServer -auto | |
Write-Host "$email belongs to: " | |
$lists = Get-DistributionGroup -ResultSize unlimited | |
$lists | where { (Get-DistributionGroupMember $_ | foreach {$_.PrimarySmtpAddress}) -contains $email } | select Name | |
} else { | |
Wite-Host "This script requires Exchange 2010 Shell to be installed. Either use this script on an Exchange server or install the EMC from the Exchange install media." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment