Update: An improved version of this script is now available here.

In the Microsoft Exchange Online Support Forums the other day there was a question about how to determine if a user was using Active Sync. Since we didn’t know how to determine in bulk if users were using Active Sync, we decided to create a script which could get this information. After doing is little research, it was pretty easy to determine if a user had configured Active Sync. The more difficult part was determining when the last sync time was. If you log into OWA, and go into options you can see the last sync time. Unfortunately, we weren’t able to determine where this information was stored in the mailbox….if you know where the Last Sync Time and Device Details are stored in a mailbox, please let us know and we’ll update the script. With that in mind, the script below just outputs users who have configured ActiveSync at some point (if you need additional information you can open a support request). This script requires that you have the EWS Managed API, which can be downloaded here.

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, suggestions, or need assistance, please email us at [email protected] .
You can download a properly formatted version of the script here.

#######################################################################################
#Active Sync Enabled Script
#
#By:Chad Mosman, 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:\Microsoft.Exchange.WebServices.dll”

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

$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,””)

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

$colusers | ForEach-Object {
If (($.ProxyAddresses -ne “”) -and ($.SubscriptionIDs -ne “”)){
$mailboxname=$_.Identity

$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”
}
}
}
}

Was this article helpful?
YesNo