The Improved Microsoft Exchange Online ActiveSync User Report script now reports ActiveSync device information and the time of the last synchronization as shown below.

UserName DeviceName DeviceID SyncStatusLast
[email protected] Android droid1258677348716 9/17/2010 7:55:5…
[email protected] MotoAndroid 4D6F746F30303133 7/6/2010 3:45:17 PM
[email protected] Android droid1258327545728 11/19/2009 5:04:…
[email protected] Android droid1258677348716 9/17/2010 7:54:5…
[email protected] Android validate 9/16/2010 8:59:5…

This script requires that you have the EWS Managed API. The best way to run the script is just to pipe the output a text file (script.ps1 > results.txt). If you have any questions, need customizations, have suggestions, or need assistance, please contact us.

You can download a properly formatted version of the script here.

#########################################################
#Active Sync Enabled? Script
#
#By:MessageOps, www.messageops.com
#
#Determines if a user has connected an ActiveSync Device to their mailbox
#
#Modify with your Microsoft Online Admin Username
$powerUser = “[email protected]
#Modify with your Microsoft Online Admin Password
$powerPass = “password”
#If you are in the APAC or EMEA Datacenters, comment out this value and uncomment out the correct value below

$uri=[system.URI] “https://red001.mail.microsoftonline.com/ews/exchange.asmx”

#APAC
#$uri=[system.URI] “https://red003.mail.apac.microsoftonline.com/ews/exchange.asmx”
#EMEA
#$uri=[system.URI] “https://red002.mail.emea.microsoftonline.com/ews/exchange.asmx”

#Modify this to point to the correct Webservices dll path
$dllpath = “C:\Program Files\Microsoft\Exchange\Web Services\1.0\Microsoft.Exchange.WebServices.dll”

#Change to 1 if you want the program to output each address being checked
#If 0 only accounts that have activesync enabled are logged
$Debug=1

#Do not modify anything below this line
########################################################

$rptCollection = @()

$password = ConvertTo-SecureString $powerPass -AsPlainText -Force

$adminCredential = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $powerUser,$password
[void][Reflection.Assembly]::LoadFile($dllpath)

$service = new-object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1)

$service.Url = $uri

$service.Credentials = New-Object System.Net.NetworkCredential($powerUser,$powerPass,””)
$PR_Last_Modified_Time = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(12296, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::SystemTime)
$Propset = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$Propset.add($PR_Last_Modified_Time)

$colUsers = get-msonlineUser -Credential $admincredential -enabled -resultsize 10000

$colusers | ForEach-Object {
If (($_.ProxyAddresses -ne “”) -and ($_.SubscriptionIDs -ne “”) -and ($_.MailboxSize -gt 0)){

$emailaddresses = $_.ProxyAddresses

ForEach ($address in $emailaddresses){

$addresstype=$address.ProxyAddress.substring(0,5)

If ($addresstype.compareto(‘SMTP:’) -eq 0){
$mailboxname = $address.ProxyAddress.Replace(“SMTP:”,””)
}
}

If ($debug -eq 1){
$mailboxname
}
$folderidcnt = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root,$MailboxName)

$folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root,$MailboxName)
$folderRoot = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service, $folderid)

$folderview = New-Object Microsoft.Exchange.WebServices.Data.FolderView(10000);

$foldercoll = $service.FindFolders($folderid,$folderview)

$foldercoll | foreach {

If (($_.displayname -eq “ExchangeSyncData”) -and ($_.Childfoldercount -gt 0)){
$MailboxName + ” ActiveSync Enabled”
$ActiveSyncDevices = $_.FindFolders($folderview)
foreach ($device in $ActiveSyncDevices){
$deviceSynced = $false
$SyncStatusLast = “Not Synced”
$InboxLastSynced = “Not Synced”
$ContactsLastSynced = “Not Synced”
$CalendarLastSynced = “Not Synced”
$folderview.PropertySet = $Propset
$ActiveSyncDevicesFolders = $device.FindFolders($folderview)
foreach ($ActiveSyncDevicesFolder in $ActiveSyncDevicesFolders) {
switch ($ActiveSyncDevicesFolder.DisplayName){
“SyncStatus” {$deviceSynced = $true
$SyncStatusLast = $null
$ptProptest2 = $ActiveSyncDevicesFolder.TryGetProperty($PR_Last_Modified_Time, [ref]$SyncStatusLast)}

}

}
if ($deviceSynced -eq $true){
$rptobj = “” | select UserName,DeviceName,Deviceid,SyncStatusLast
$rptobj.UserName = $MailboxName
$devicearry = $device.Displayname.split(“-“)
if ($devicearry.Count -ge 2){
$rptobj.DeviceName = $devicearry[1] $rptobj.Deviceid = $devicearry[2] }
if ($SyncStatusLast -ne “Not Synced”){$rptobj.SyncStatusLast = $SyncStatusLast.ToLocalTime()}
else{$rptobj.SyncStatusLast = $SyncStatusLast}
$rptCollection += $rptobj
}
}
}
}
}
}
$rptCollection

Was this article helpful?
YesNo