#Get all mailboxes that have an active sync partnership:
$Mailboxes = Get-CASMailbox -Filter{HasActiveSyncDevicePartnership -eq $true}| select name, servername, DistinguisheDName, ActiveSyncMailboxPolicy
$NumberWiped = 0
$NumberSent =0
$TotalCount = 0
Foreach ($mailbox in $Mailboxes)
{
$Name = $mailbox.Name
$DName= $mailbox.distinguisheDName
$Stats = Get-ActiveSyncDeviceStatistics -mailbox $DName
if ($Stats -ne $null)
{
$bodySummary = $bodySummary + "
User "+ $mailbox.Name +" is on " +$mailbox.ServerName + " using the " +$mailbox.ActiveSyncMailboxPolicy + " policy"
$TotalCount ++
}
}
$body = "Executive Summary:
There are " + $TotalCount +" mailboxes that have a current Active Sync partnership:
"
$body = $body + $bodySummary
$bodydetail = $bodydetail + "
Device Information:"
Foreach ($mailbox in $Mailboxes)
{
$Name = $mailbox.Name
$DName= $mailbox.distinguisheDName
$Stats = Get-ActiveSyncDeviceStatistics -mailbox $DName
if ($Stats.count -gt 1)
{
$bodydetail = $bodydetail +"
User "+ $mailbox.Name + " has the following " + $Stats.Count + " devices:
"
}
elseif($Stats.count -lt 2 -and $Stats -ne $null)
{
$bodydetail = $bodydetail +"
User "+ $mailbox.Name + " has the following device:
"
$bodydetail = $bodydetail + $Stats.count
}
if ($Stats.count -lt 2 -and $Stats -ne $null)
{
if ($Stats.DeviceWipeRequestTime -ne $null)
{
if ($Stats.DeviceWipeAckTime -ne $null)
{
$NumberWiped ++
$bodydetail = $bodydetail +"
This device was wiped on " + $Stats.DeviceWipeAckTime.ToString()
$bodydetail = $bodydetail +"
Click here to remove this active sync partnership:"
}
else
{
$NumberSent ++
$bodydetail = $bodydetail +">
This device was sent the wipe command on " + $Stats.DeviceWipeRequestTime.ToString() +""
$bodydetail = $bodydetail +"
Click here to remove this active sync partnership:Remove Partnership"
}
}
$bodydetail = $bodydetail + " "
$bodydetail = $bodydetail + "FirstSyncTime : " + $Stats.FirstSyncTime +" "
$bodydetail = $bodydetail + "LastPolicyUpdateTime : " + $Stats.LastPolicyUpdateTime +" "
$bodydetail = $bodydetail + "LastSyncAttemptTime : " + $Stats.LastSyncAttemptTime +" "
$bodydetail = $bodydetail + "LastSuccessSync : " + $Stats.LastSuccessSync +" "
$bodydetail = $bodydetail + "DeviceType : " + $Stats.DeviceType +" "
$bodydetail = $bodydetail + "DeviceID : " + $Stats.DeviceID +" "
$bodydetail = $bodydetail + "DeviceUserAgent : " + $Stats.DeviceUserAgent +" "
$bodydetail = $bodydetail + "DeviceWipeSentTime : " + $Stats.DeviceWipeSentTime +" "
$bodydetail = $bodydetail + "DeviceWipeRequestTime : " + $Stats.DeviceWipeRequestTime +" "
$bodydetail = $bodydetail + "DeviceWipeAckTime : " + $Stats.DeviceWipeAckTime +" "
$bodydetail = $bodydetail + "DeviceModel : " + $Stats.DeviceModel +" "
$bodydetail = $bodydetail + "DeviceFriendlyName : " + $Stats.DeviceFriendlyName +" "
$bodydetail = $bodydetail + "DeviceOS : " + $Stats.DeviceOS +" "
$bodydetail = $bodydetail + "DeviceOSLanguage : " + $Stats.DeviceOSLanguage +" "
$bodydetail = $bodydetail + "DevicePhoneNumber : " + $Stats.DevicePhoneNumber +" Identity : " + $Stats.Identity +"
"
}
elseif ($Stats.Count -gt 1)
{
foreach ($Stat in $Stats)
{
if ($Stat.DeviceWipeRequestTime -ne $null)
{
if ($Stat.DeviceWipeAckTime -ne $null)
{
$Wiped= ""
$NumberWiped ++
$bodydetail = $bodydetail +"
This device was wiped on " + $Stat.DeviceWipeAckTime.ToString()
}
else
{
$NumberSent ++
$bodydetail = $bodydetail +"
This device was sent the wipe command on " + $Stat.DeviceWipeRequestTime.ToString()+""
$bodydetail = $bodydetail +"
Click here to remove this active sync partnership:Remove Partnership"
}
}
$bodydetail = $bodydetail + "
| FirstSyncTime | : " + $stat.FirstSyncTime +" |
| LastPolicyUpdateTime | : " + $stat.LastPolicyUpdateTime +" |
| LastSyncAttemptTime | : " + $stat.LastSyncAttemptTime +" |
| LastSuccessSync | : " + $stat.LastSuccessSync +" |
| DeviceType | : " + $stat.DeviceType +" |
| DeviceID | : " + $stat.DeviceID +" |
| DeviceUserAgent | : " + $stat.DeviceUserAgent +" |
| DeviceWipeSentTime | : " + $stat.DeviceWipeSentTime +" |
| DeviceWipeRequestTime | : " + $stat.DeviceWipeRequestTime +" |
| DeviceWipeAckTime | : " + $stat.DeviceWipeAckTime +" |
| LastPingHeartbeat | : " + $stat.LastPingHeartbeat +" |
| DeviceModel | : " + $stat.DeviceModel +" |
| DeviceIMEI | : " + $stat.DeviceIMEI +" |
| DeviceFriendlyName | : " + $stat.DeviceFriendlyName +" |
| DeviceOS | : " + $stat.DeviceOS +" |
| DeviceOSLanguage | : " + $stat.DeviceOSLanguage +" |
| DevicePhoneNumber | : " + $stat.DevicePhoneNumber +" |
| Identity | : " + $stat.Identity +" |