This script will count the number of email addresses that created via Email Address Policy for all Mailboxes.
This script is to help Exchange Administrator get a report of the total number of email addresses that created via Email Address Policy for each Mailbox.
Step1: Start the Exchange Management Shell. To run the script in the Windows PowerShell Console, type the one command< Script Path> at the Windows PowerShell Console.
For example, type C:\Script\CountAddressCreatebyPolicy.ps1

Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.
#Get All Mailboxes
$MBXs = Get-Mailbox -ResultSize Unlimited | Where{$_.Name -notlike "DiscoverySearchMailbox*"}
$Result = @{}
#Count the Number
Foreach ($MBX in $MBXs){
#Get Mailbox's Email Address
$Addresses = $MBX.EmailAddresses | Where{$_.Prefix -like "SMTP"} |Select AddressString -ExpandProperty AddressString
#Check Each Address
Foreach ($Address in $Addresses){
$count = 0
#Get some Property
$FName = (Get-User $Address).FirstName
$FNameInitial = $FName.Substring(0,1)
$LName = (Get-User $Address).LastName
$LNameInitial = $LName.Substring(0,1)
$Alias = (Get-Mailbox $Address).Alias
#Get all the Templates
$Templates = Get-EmailAddressPolicy | Select EnabledPrimarySMTPAddressTemplate -ExpandProperty EnabledPrimarySMTPAddressTemplate
#Count the Number
Foreach ($Template in $Templates){
$Template = $Template.Replace("%m",$Alias)
$Template = $Template.Replace("%g",$FName)
$Template = $Template.Replace("%1g",$FNameInitial)
$Template = $Template.Replace("%s",$LName)
$Template = $Template.Replace("%1s",$LNameInitial)
If($Template -eq $Address){$count++}
}
}
$Result.Add($MBX.Alias,$count)
}
$Result
#Get All Mailboxes $MBXs = Get-Mailbox -ResultSize Unlimited | Where{$_.Name -notlike "DiscoverySearchMailbox*"} $Result = @{} #Count the Number Foreach ($MBX in $MBXs){ #Get Mailbox's Email Address $Addresses = $MBX.EmailAddresses | Where{$_.Prefix -like "SMTP"} |Select AddressString -ExpandProperty AddressString #Check Each Address Foreach ($Address in $Addresses){ $count = 0 #Get some Property $FName = (Get-User $Address).FirstName $FNameInitial = $FName.Substring(0,1) $LName = (Get-User $Address).LastName $LNameInitial = $LName.Substring(0,1) $Alias = (Get-Mailbox $Address).Alias #Get all the Templates $Templates = Get-EmailAddressPolicy | Select EnabledPrimarySMTPAddressTemplate -ExpandProperty EnabledPrimarySMTPAddressTemplate #Count the Number Foreach ($Template in $Templates){ $Template = $Template.Replace("%m",$Alias) $Template = $Template.Replace("%g",$FName) $Template = $Template.Replace("%1g",$FNameInitial) $Template = $Template.Replace("%s",$LName) $Template = $Template.Replace("%1s",$LNameInitial) If($Template -eq $Address){$count++}}} $Result.Add($MBX.Alias,$count) } $Result
Exchange 2010, Exchange 2013
PowerShell 2.0