#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 + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "
FirstSyncTime : " + $Stats.FirstSyncTime +"
LastPolicyUpdateTime : " + $Stats.LastPolicyUpdateTime +"
LastSyncAttemptTime : " + $Stats.LastSyncAttemptTime +"
LastSuccessSync : " + $Stats.LastSuccessSync +"
DeviceType : " + $Stats.DeviceType +"
DeviceID : " + $Stats.DeviceID +"
DeviceUserAgent : " + $Stats.DeviceUserAgent +"
DeviceWipeSentTime : " + $Stats.DeviceWipeSentTime +"
DeviceWipeRequestTime : " + $Stats.DeviceWipeRequestTime +"
DeviceWipeAckTime : " + $Stats.DeviceWipeAckTime +"
DeviceModel : " + $Stats.DeviceModel +"
DeviceFriendlyName : " + $Stats.DeviceFriendlyName +"
DeviceOS : " + $Stats.DeviceOS +"
DeviceOSLanguage : " + $Stats.DeviceOSLanguage +"
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 + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $bodydetail = $bodydetail + "" $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 +"

" } } } function sendmail([string] $body) { $SmtpClient = new-object system.net.mail.smtpClient $MailMessage = New-Object system.net.mail.mailmessage $SmtpClient.Host = "smtp.host" $mailmessage.from = "From.Address@from.com" $mailmessage.To.add("to.address@to.com") $mailmessage.Subject = "Mailboxes that have an Active Sync Device Partnership" $MailMessage.IsBodyHtml = $False $mailmessage.Body = $body $MailMessage.IsBodyHtml = $TRUE $smtpclient.Send($mailmessage) } $body = $body + "

There are $NumberWiped devices that have been wiped." $body = $body + "
There are $NumberSent devices that have a pending wipe command.
" $Body = $Body + $BodyDetail sendmail($Body) $bodydetail = "" $Name = "" $bodySummary = ""