Just a quick post on useful PowerShell commands to get some ActiveSync config and statistics. Basic, but I wanted them quickly accessible for my own reference đŸ™‚

Get-MailboxStatistics -Identity username | fl

Get device statistics:

Get-ActiveSyncDeviceStatistics -Mailbox username

Get more info for specific user, for example if they have ActiveSyncAllowedDeviceIDs configured.

Get-CASMailbox -Identity username | fl *ActiveSync*

Get a list of users and info regarding their device:

Get-Mailbox -ResultSize:Unlimited | ForEach {Get-ActiveSyncDeviceStatistics -Mailbox:$_.Identity} | ft Identity,Devicemodel,DeviceOS,DeviceUserAgent,DeviceType,LastSuccessSync

Will more or less output the same result but another syntax:

$Mailboxes = Get-Mailbox –ResultSize Unlimited
$Devices = $Mailboxes | %{Get-ActiveSyncDeviceStatistics -Mailbox $_.Identity}
$Devices | ft Identity,DeviceType,DeviceModel,DeviceOS,DeviceFriendlyName,DeviceUserAgent

To remove ONE of the DeviceID’s specified in ActiveSyncAllowedDeviceIDs:

$CasDevice = Get-CasMailbox username
$CasDevice.ActiveSyncAllowedDeviceIDs -= "12345111"
Set-CasMailbox username -ActiveSyncAllowedDeviceIDs $CasDevice.ActiveSyncAllowedDeviceIDs

Instead of allowing all users to use ActiveSync, it’s pretty common I configure the TMG/ISA to only allow a specific GROUP to sync. Then it would be great to be able to get a list of those users and their ActiveSyncAllowedDeviceIDs, just to doublecheck no user is configured incorrectly. Now, bear in mind I’m no PowerShell wizard so if you have a way of doing this without involving a vbscript – please comment! I’d love to solve it without a script.

' Bind to group with Distinguished Name.
strGroup = "CN=GROUPNAME,OU=Organization,DC=lab,DC=com"
strOutput = "C:\Temp\ActiveSync_members.txt"

Set objGroup = GetObject("LDAP://" & strGroup)

Wscript.Echo "Outputs the members of the group: " & strGroup
Wscript.Echo "Both to screen and file: " & strOutput
Wscript.Echo ""

Set fso = CreateObject("Scripting.FileSystemObject")

' Change name in case the file exists
'Delete file
if fso.FileExists (strOutput) then
 Set dFile = fso.GetFile(strOutput)
end If

Set ts = fso.OpenTextFile(strOutput, 8, True)

' Get members

For Each objMember In objGroup.Members
 Wscript.Echo objMember.sAMAccountName
 ts.WriteLine (objMember.sAMAccountName)

Then we have a script to get the result!

Get-Content C:\Temp\ActiveSync_members.txt | Foreach-Object {Get-CASMailbox -Identity $_ | select sAMAccountName,ActiveSyncAllowedDeviceIDs}

Hope you find them useful and please comment if you have any great PowerShell commands you often use.