Exchange-Scripts/search-email-addresses.ps1

27 lines
840 B
PowerShell

# By: Jeremy Berkleef
# The following script will search email addresses based on the search term and spit out all the aliases
# Ask the user what we need to search for
$searchTerm = Read-Host -Prompt 'Input Query'
#List Aliases
get-mailbox | Where-Object {$_.EmailAddresses -like "$searchTerm"} |ForEach-Object{
$host.UI.Write("White", $host.UI.RawUI.BackGroundColor, "`nUser Name: " + $_.DisplayName+"`n")
for ($i=0;$i -lt $_.EmailAddresses.Count; $i++)
{
$address = $_.EmailAddresses[$i]
$host.UI.Write("Green", $host.UI.RawUI.BackGroundColor, $address.AddressString.ToString()+"`t")
if ($address.IsPrimaryAddress)
{
$host.UI.Write("Blue", $host.UI.RawUI.BackGroundColor, "Primary Email Address`n")
}
else
{
$host.UI.Write("Red", $host.UI.RawUI.BackGroundColor, "Alias`n")
}
}
}