#get mailboxes and iterate through each email address and shows it either primary or an alias
get-mailbox | foreach{
$host.UI.Write("Blue", $host.UI.RawUI.BackGroundColor, "`nUser Name: " + $_.DisplayName+"`n")
for ($i=0;$i -lt $_.EmailAddresses.Count; $i++)
{
$address = $_.EmailAddresses[$i]
$host.UI.Write("Blue", $host.UI.RawUI.BackGroundColor, $address.AddressString.ToString()+"`t")
if ($address.IsPrimaryAddress)
{
$host.UI.Write("Green", $host.UI.RawUI.BackGroundColor, "Primary Email Address`n")
}
else
{
$host.UI.Write("Green", $host.UI.RawUI.BackGroundColor, "Alias`n")
}
}
}
Save this entire script as a .ps1 file (Powershell script file) e.g “ShowEmailIDs.ps1”, and then place it in the “Scripts” folder in MS Exchange Installation folder which is noramlly “C:\Program Files\Microsoft\Exchange Server\Scripts”. Then open Exchange Management Shell and just type the name of .ps1 file e.g. ShowEmailIDs.ps1 and press enter. It will show result like this
User Name: [email protected] [email protected] Primary Email Address
User Name: [email protected] [email protected] Primary Email Address
Note: U can also put a filter for get-mailbox in above mentioned script to run this script for a specific domain like this
get-mailbox | Where{ $_.PrimarySmtpAddress -like “*domain.lab” }| foreach{