Friday, April 29, 2011

Report on All ActiveSync Devices Attached to Exchange Mailboxes

Someone wearing a tie decided that we needed a report showing the stats of ActiveSync devices connected to our Exchange environment. Here my Exchange PowerShell script solution to the request.

#AD Setting for Multi Domain Forest
Set-ADServerSettings -ViewEntireForest $true

#Retrieve All Mailboxes...Sort by Display Name -resultsize unlimited
$mailboxes = get-mailbox -resultsize unlimited | sort -property DisplayName |
select-object DisplayName,Alias,Identity

foreach ($mailbox in $mailboxes)
{
#Pull ActiveSync Information for the Mailbox
$devices = get-activesyncdevicestatistics -mailbox $mailbox.identity

#Check to See if Mailbox has ActiveSync Device(s)
if ($devices)
{
#Report on All Devices for Mailbox
foreach ($device in $devices)
{
#Create New PowerShell Object and Assign Data to It
$uEntry = new-Object PSObject
$uEntry | add-Member -memberType noteProperty -name "Display Name" -Value $mailbox.DisplayName
$uEntry | add-Member -memberType noteProperty -name "Alias" -Value $mailbox.Alias
$uEntry | add-Member -memberType noteProperty -name "Device Type" -Value $device.DeviceType
$uEntry | add-Member -memberType noteProperty -name "Device Model" -Value $device.DeviceModel
$uEntry | add-Member -memberType noteProperty -name "First Sync Time" -Value $device.FirstSyncTime
$uEntry | add-Member -memberType noteProperty -name "Last Successful Sync" -Value $device.LastSuccessSync
$uEntry | add-Member -memberType noteProperty -name "Last Sync Attempt" -Value $device.LastSyncAttemptTime
$uEntry | add-Member -memberType noteProperty -name "Device OS" -Value $device.DeviceOS
$uEntry | add-Member -memberType noteProperty -name "Device ID" -Value $device.DeviceId
#Add Entry to Summary Array
$Summary += $uEntry

}
}
}

#Export Summary Info to CSV File
$Summary | Export-CSV ActiveSync_Devices.csv -NoTypeInformation

No comments: