Share via


ActiveSync Reporting with PowerShell - Users with a partnership and a list of their devices

 

This script was used by a colleague to gather information for licensing purposes. Since users can have more than one device partnership (which means its a multivalued attribute), and a user (in 2010, at least) can have a maximum of 10 partnerships, it was necessary to parse through that value so that we could get a list of ALL the devices. While this bit information may not be necessary for licensing purposes, I think it's still one of those "good to know" type of things. And, I just wanted to practice parsing through the information and writing it out to a file :). 

 

Just as an FYI, once the maximum of 10 devices is reached, a user will receive an error code of STATUS_CODE_MAXIMUMDEVICESREACHED when trying to create new partnerships. They will also see a warning in OWA when viewing the "Mobile Phones" tab indicating that they have reached the maximum number of allowed partnerships, and that no new partnerships can be created until some of the others have been removed.


 

$output_file="c:\scripts\test.txt"

$users = get-casmailbox –resultSize Unlimited | where {$_.HasActiveSyncDevicePartnership -eq $true}

 

$users | foreach {$id = $_.identity; $mbstats = get-activesyncdevicestatistics -mailbox $id

 

If ($mbstats.DeviceModel -ne 1) {$devices = $mbstats.DeviceModel; $Sync = $mbstats.LastSuccessSync

        for ($i=0; $i-lt $devices.count; $i++) {"$report$($id), $($devices[$i]), $($sync[$i])" | add-content $output_file}

 

    }

    else {"$report$($id), $($mbstats.DeviceModel), $($mbstats.LastSuccessSync)" | add-content $output_file}

}

 


 

So, given the fact that each user can have a maximum of 10 partnerships, what can we do if a user reaches the maximum number of partnerships?

 

Well, once again, PowerShell to the rescue!

 


 

This bit of code will delete all ActiveSync Partnerships that are older than 7 days. Be sure to adjust the time period to a number that suits your environment! This tidbit of code is courtesy of my friend Jim Martin (also a MSFT employee).

 

#Find all of your users who have ActiveSync Partnerships:

1.) $eas = Get-CASMailbox | where { $_.HasActiveSyncDevicePartnership -eq $True } 

#Find all users within the ActiveSync Partnership list that has a “LastSyncAttempttime” less than X amount of days, here we set a week:

2.) $del = $eas | ForEach-Object { Get-ActiveSyncDeviceStatistics -Mailbox $_.Identity | where { $_.LastSyncAttempttime -lt (Get-date).adddays(-7) }}

#Remove all ActiveSync Partnerships older than 7 days:

3.) $del | ForEach-Object { Remove-ActiveSyncDevice $_.identity -Confirm:$False }

 


Many thanks to Ethan McConnell and Jim Martin for assisting with this post.

Comments

  • Anonymous
    January 01, 2003
    Gavin, there are a number of ways with powershell to send output to a file. A couple of things you could do here would be to create the text file in advanced. this should eliminate any permissions issues with creating the file on the c: drive. You could also try a different drive path (d, for example). Also, are you sure the query is actually grabbing data? After the script has run, try typing $mbstats and hit enter, and make sure some data is displayed on the screen. If not, then the query is not finding any data that matches the query statement (for whatever reason).

  • Anonymous
    August 08, 2013
    I recently published a script for removing old active sync partnerships from environment that might come in handy in this scenario, Please check same below gallery.technet.microsoft.com/.../Remove-old-Active-sync-447a0687 Also have a script that generates device report in csv file or for SQL upload. Will send same separately.

  • Anonymous
    December 06, 2013
    The comment has been removed

  • Anonymous
    December 06, 2013
    The comment has been removed

  • Anonymous
    April 15, 2014
    I have run this - but it doesnt output to the test.txt file, any idea why?

    Gavin.

  • Anonymous
    February 27, 2017
    Hello I'm looking for a way to identify mailboxes that have exceeded their max ActiveSync partnership limit, any help would be appreciated. thx.