Exchange Script: Find ActiveSync Device Statistics for users in a Distribution Group

Scenario: You want to Find ActiveSync Device Statistics for users that are in a Distribution Group. If the Distribution Group does not contain members, it will not send the email. If it contains members, it will send an email for each member. Copy the content below and paste it into a .ps1 file and execute from Exchange Mangaement Shell.   
$mbox = Get-DistributionGroup “group-name”| Get-DistributionGroupMember
If ($mbox -ne $null)
{
$email = $mbox | ForEach {
$name = $_ | Select Name |Out-String
$body = get-activesyncdevicestatistics -mailbox $_.name | Sort DeviceFriendlyName | FT DeviceFriendlyName, DeviceModel, LastSyncAttemptTime, LastSuccessSync | Out-string
$SmtpClient = new-object system.net.mail.smtpClient
$MailMessage = New-Object system.net.mail.mailmessage
$SmtpClient.Host = “servername”
$mailmessage.from = (“EASMonitoring@domain.com”)
$mailmessage.To.add(“easstatistics@domain.com“)
$mailmessage.Subject = “EAS Statistics”
$mailmessage.Body = “
EAS Statistics for:$name
$body

$smtpclient.Send($mailmessage)
}
}
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: