(UPDATED) How to Get a Report of Active Sync Devices in Exchange 2010/Exchange 2013

ActiveSync, Exchange 2010, Exchange 2013, Scripting

***UPDATE***

 

There was a lot of feedback from people who wanted extra items and fields added in so I edited the original script.  It will now also include the users Primary SMTP Address, LastSyncAttemptTime, and LastSyncSuccessTime.  Also edited it for environments with over a thousand mailboxes. Below is the updated script code:

The new output will look like this:

image

image

 

Ever had the need to get a nice report of all active sync devices in your Exchange organization?  Well then I have the script for you!

This script will get through all active sync devices, and match them up with their respective owners.  It will also output the Device Type, Device Model, and most importantly the Device OS.

Why is this important?  As some of you remember shortly back, there was an issue with Apple iOS devices causing excessive logging on Exchange Mailbox servers.  As part of the way to fix that you could block or quarantine those devices.  You most likely want to be able to see who you are blocking though, so you you know who your going to annoy and warn them preemptively.

The script requires 4 parameters to run, and should be run from an Exchange Management Shell:

  1. SMTPServer = SMTP server as the report will send you a copy of the report
  2. SMTPFrom = The FROM address of the email
  3. SMTPTo = The recipient of the email
  4. ExportPath = The folder location where you want the CSV export of the report. 

For example, to send the report to admin@port25guy.com using the SMTP server relay.port25guy.com, have the from address be reports@port25guy.com and export the CSV to C:\Reports:

Get-ActiveSyncReport.ps1 –exportpath C:\Reports –smtpserver relay.port25guy.com –smtpfrom reports@port25guy.com –smtpto admin@port25guy.com

After running that, if we check the C:\reports folder we should have a nice CSV export:

image

And a nice email report in your inbox:

 

image

You can download the script from the link below, just rename the file to extension .ps1

Here is the ***UPDATED** script block as well:

 

### BEGINNING OF SCRIPT

#####
#
# Get-ActiveSyncDeviceReport
# Author: Paul Ponzeka
# Website: port25guy.com
# email ponzekap2 at gmail dot com
#
######
param(
    [Parameter(Mandatory = $true)]
    [string] $SMTPServer = “”,
    [Parameter(Mandatory = $true)]
    [string] $SMTPFrom = “”,
    [Parameter(Mandatory = $true)]
    [string] $SMTPTo = “”,
    [Parameter(Mandatory = $true)]
    [string] $exportpath = “”
    )

#######
#
# HTML Formatting Section
# Thanks to Paul Cunningham at http://exchangeserverpro.com/
#
#######
#
#
#
######
$style = “<style>BODY{font-family: Arial; font-size: 10pt;}”
$style = $style + “TABLE{border: 1px solid black; border-collapse: collapse;}”
$style = $style + “TH{border: 1px solid black; background: #dddddd; padding: 5px; }”
$style = $style + “TD{border: 1px solid black; padding: 5px; }”
$style = $style + “</style>”

$messageSubject = “ActiveSync Device Report”

$message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
$message.Subject = $messageSubject
$message.IsBodyHTML = $true

####  Get Mailbox

$EASDevices = “”
$AllEASDevices = @()

$EASDevices = “”| select ‘User’,’PrimarySMTPAddress’,’DeviceType’,’DeviceModel’,’DeviceOS’, ‘LastSyncAttemptTime’,’LastSuccessSync’
$EasMailboxes = Get-Mailbox -ResultSize unlimited
foreach ($EASUser in $EasMailboxes) {
$EASDevices.user = $EASUser.displayname
$EASDevices.PrimarySMTPAddress = $EASUser.PrimarySMTPAddress.tostring()
    foreach ($EASUserDevices in Get-ActiveSyncDevice -Mailbox $EasUser.alias) {
    $EASDeviceStatistics = $EASUserDevices | Get-ActiveSyncDeviceStatistics
    $EASDevices.devicetype = $EASUserDevices.devicetype
    $EASDevices.devicemodel = $EASUserDevices.devicemodel
    $EASDevices.deviceos = $EASUserDevices.deviceos
    $EASDevices.lastsyncattempttime = $EASDeviceStatistics.lastsyncattempttime
    $EASDevices.lastsuccesssync = $EASDeviceStatistics.lastsuccesssync
    $AllEASDevices += $EASDevices | select user,primarysmtpaddress,devicetype,devicemodel,deviceos,lastsyncattempttime,lastsuccesssync
    }
    }
$AllEASDevices = $AllEASDevices | sort user
$AllEASDevices
$AllEASDevices | Export-Csv $exportpath\ActiveSyncReport.csv

######
#
# Send Email Report
#
########

$message.Body = $AllEasDevices | ConvertTo-Html -Head $style

$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($message)

##END OF SCRIPT

Also, special thanks to Paul Cunningham at http://exchangeserverpro.com.  He wrote the HTML formatting section in the script that makes this look nice and pretty, versus my junky plain text (http://exchangeserverpro.com/powershell-html-email-formatting).  If you haven’t check out Paul’s site you should, he has great information on there. 

Hope you find the script helpful!

Comments;

  1. Being a novice a PowerShell I found this to be a fantastic script. How would I modify it if I wanted to add the attribute “LastSyncAttemptTime” please?

    Reply
  2. jared

    This is a great script. The only I added was -resultsize unlimited… The question I had is what if we wanted to get more device details such as LastSuccessSync? thanks again.

    Reply
  3. Hi

    Is there a way to narrow this down to a date specific range, say all activesync partnerships that happened in the last month?
    Reason I ask, is that I get multiple devices for some users that only have one smart phone.
    All I can think is that it is giving you all the previous devices that the user used to access their mail?

    Reply
  4. Tim Adams

    To Jared,

    Where did you add in the -resultsize unlimited?

    Regards,
    Tim

    Reply
    1. Port25Guy Post author

      Get mailbox should become get mailbox _resultsize unlimited

      Reply
      1. Niyi A

        Nice script.

        I got this error each time I ran it.

        PS D:\Jo> .\EA.ps1

        cmdlet EA.ps1 at command pipeline position 1
        Supply values for the following parameters:
        SMTPServer: 172.29.11.11
        SMTPFrom: db1@test.com
        SMTPTo: db2@test.com
        exportpath: d:\jo
        Get-Mailbox : The term ‘Get-Mailbox’ is not recognized as the name of a
        cmdlet, function, script file, or operable program. Check the spelling of the
        name, or if a path was included, verify that the path is correct and try agai
        At D:\Jo\EA.ps1:55 char:16
        + $EasMailboxes =Get-Mailbox -ResultSize unlimited
        + ~~~~~~~~~~~
        + CategoryInfo : ObjectNotFound: (Get-Mailbox:String) [], Comman
        NotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException

        Exception calling “Send” with “1” argument(s): “The SMTP server requires a
        secure connection or the client was not authenticated. The server response
        was: 5.7.1 Client was not authenticated”
        At D:\Jo\EA.ps1:82 char:1
        + $smtp.Send($message)
        + ~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : SmtpException

        Reply
  5. Great script! How do I add “DeviceFriendlyName” and “LastSuccessSync” to this script? I tried but was only able to add a column in exel for these parameters.

    Thank you,
    John

    Reply
  6. Kevin

    Has anyone figured out how to add the following parameters to this script:

    PrimarySMTPAddress
    LastSyncAttemptTime
    LastSuccessSync

    I’ve tried adding them in, but they keep coming up as blank columns in my report.

    Thanks.

    Reply
    1. Port25Guy Post author

      Kevin,

      Thats for the feedback. I’ve updated the site with the updated script.

      Reply
  7. Christian Andersson

    Hello!

    Thanks for this great script!
    Is it possible to add the users “company” attribute from the Active Directory in the script?

    Regards, Christian

    Reply
  8. Dave

    I am getting Warning: You currently have 10 Exchange ActiveSync partnerships out of 10 maximum partnerships allowed per user. After you reach the maxiumu, no new partnerships can be created until you remove some from your account.
    What would I need to do so I do not get this and get an accurate count?

    Reply
    1. Port25Guy Post author

      Exchange throttling policies restrict you to 10 ActiveSync Device partnerships by default. Remove some of the stale ones with Remove-ActiveSyncDevice.

      Reply
  9. pyore

    Hi,
    Great script thanks. Doe the script have to be run on each cas server in a 2010 org?

    Reply
  10. Anthony

    Why are some of the DeviceOS categories blank? Is it because it’s running an older version of the OS and it’s not being reported?

    Reply
  11. Hi,

    Same question as Anthony.
    Some DeviceType and DeviceModel only contains “iPhone”.

    Have manually checked some of these and they are iphones with ios 4.x.x and 5.x.x

    But in exchange if I look up a user with one of these devices all the decive information is there for the script to display.

    //Best Regards
    Patrik

    Reply
  12. Jussi

    Any chance adding IME code into the report? I tried it actually with deviceimei, but just cannot get it working. Anyone?

    Reply
    1. Gus

      DeviceIMEI will work however Apple devices do not publish IMEI to exchange. Most other brands will (i.e. windows, blackberry, android).

      Reply
  13. Eric

    Great Script! But… it missed some user… might be only our setup here but some Get-activesyncDevice -mailbox do not return any thing.
    I found out because my own name was not in the final list and I have a working device…
    So I dig it… found out that my device was in the Get-ActiveSyncDevice command but it did not contain the user info…(UserDisplayName is empty) If I run Get-ActiveSyncDeviceStatistics toward my mailbox it does reply with my device…
    Thanks,

    Reply
  14. Sinan

    Ok Great report thank you.
    Please add Device ID or IMEI number…

    Reply
    1. Joshua Cooper

      Does anyone know how to add device ID and or IMEI number?

      Reply
  15. Hartmann

    Please let me thanks this guy “Port25Guy”!

    Your script was awesome! I’ve edited it to add -Bcc parameter to hide some recipients, You’re the man!!!!!

    My pleasure to find this!

    Reply
  16. Pingback: Information Technology | Current Affairs | Philosophy | Life in General » List all Mobile Devices connected to Office365 (Exhange 2010/2013) – PowerShell

  17. Pingback: Powershell Bulk Load ActiveSync Device IDs into Exchange | A WordPress Site

  18. Jim Sutton

    Great script! Is there a way to limit this script to only report devices that haven’t synced in the last 30 days?

    Reply
  19. RX

    Thanks for putting together and explaining so well. I am wondering if you can guide me on how I could add some AD related user account information into the Output some of the extended attributes for instance Office or Division etc.

    Reply
  20. Davide

    Hello! great script!
    I would like to schedule the script as I enter the info without having to always write?

    Reply
  21. Bob

    How would you add a parameter to filter this only from the last 30 days?

    Reply
  22. Loon

    Thanks for this, I am getting an error when I run it either on the server or on a workstation with the shell:

    The Get-ActiveSyncDevice cmdlet can only retrieve mobile device information for 15 mailboxes.

    Any ideas ?

    Reply
  23. Lisa

    Dear John,

    Thanks for the great script, wish to have two more info in the output

    DeviceType
    DeviseUserAgent

    Could you please update your script or just mail me. Thank you.

    Reply
  24. Hi
    Is there a way to narrow this down to a date specific range, say all activesync partnerships that happened in the last month?
    Reason I ask, is that I get multiple devices for some users that only have one smart phone.
    All I can think is that it is giving you all the previous devices that the user used to access their mail?

    Reply
  25. Wayne

    Will this script be updated to use the Get-MobileDevice instead of Get-ActiveSyncDeviceStatistics?

    Reply
  26. linda

    How do I add a command for only one exchange server and not all servers in the organisation

    Reply
  27. Johnny

    Thank you for the script, it worked like a charm. May the IT Gods bless thee!

    Reply
  28. Duane

    Great Script!
    Been using this for a while now….a few random errors come up when running it. Its completely random when it hits…not the same user twice. The script is going through roughly 52K accounts.

    Get-ActiveSyncDeviceStatistics : Unable to read this mailbox’s folder data in order to determine if the default folders are present.
    At .\Get.ActivesyncReport2.ps1:77 char:77
    + $EASDeviceStatistics = $EASUserDevices | Get-ActiveSyncDeviceStatisti
    cs <<<<
    + CategoryInfo : ReadError: () [Get-ActiveSyncDeviceStatistics], ConnectionFailedTransientException
    + FullyQualifiedErrorId : D0DDB72E,Microsoft.Exchange.Management.Tasks.Get
    MobileDeviceStatistics

    Get-ActiveSyncDeviceStatistics : Cannot set table columns.
    At .\Get.ActivesyncReport2.ps1:77 char:77
    + $EASDeviceStatistics = $EASUserDevices | Get-ActiveSyncDeviceStatisti
    cs <<<<
    + CategoryInfo : ReadError: () [Get-ActiveSyncDeviceStatistics], ConnectionFailedTransientException
    + FullyQualifiedErrorId : D0DDB72E,Microsoft.Exchange.Management.Tasks.Get
    MobileDeviceStatistics

    Get-ActiveSyncDeviceStatistics : Cannot get hierarchy table.
    At .\Get.ActivesyncReport2.ps1:77 char:77
    + $EASDeviceStatistics = $EASUserDevices | Get-ActiveSyncDeviceStatisti
    cs <<<<
    + CategoryInfo : ReadError: () [Get-ActiveSyncDeviceStatistics], ConnectionFailedTransientException
    + FullyQualifiedErrorId : CE2D0639,Microsoft.Exchange.Management.Tasks.Get
    MobileDeviceStatistics

    Any suggestions would be great!

    Thanks
    Duane

    Reply
  29. ML

    I am happy to find this post. Script works great.
    Is there a way to pull in AD attributes?
    I would like to sort users by department.

    Reply
  30. I am pretty new to Powershell Scripting, I like the script, but how can I add the “DeviceAccessState” to see which device is blocked or allowed. I tried to add
    $EASDevices.DeviceAccessState = $EASDeviceStatistics.DeviceAccessState
    But the field was empty :-(

    Reply
  31. Ozz

    Hello,
    Thanks for the write up, I am attempting to generate the ActiveSyncReport.csv with output to my desktop, I managed to get a blank report with the changes I made to original script.
    After a few changes I have something that has been running for a few minutes w/o output so far. Can you take a peek at my version of your script?

    Reply
    1. Ozz

      I did manage to get the output, was missing a ‘\’….
      Now I have been faced with another question. In a multi site situation how can I query for location? Thanks.

      Reply
  32. Steven Hodges

    AWESOME! I love this script, It is such a life saver. Thank you for sharing your work!

    If it could also pull the GUID of the device that would be great. You can pull the GUID with the following command:

    Get-ActiveSyncDeviceStatistics -Mailbox emailaddress@yourdomain.com

    However, I am new to scripting and have not been able to determine the parameters to add to get the GUID.

    Reply
    1. Steven Hodges

      I found my error. Modified the script to pull GUID

      ### BEGINNING OF SCRIPT

      #####
      #
      # Get-ActiveSyncDeviceReport
      # Author: Paul Ponzeka
      # Website: port25guy.com
      # email ponzekap2 at gmail dot com
      #
      ######
      param(
      [Parameter(Mandatory = $true)]
      [string] $SMTPServer = “”,
      [Parameter(Mandatory = $true)]
      [string] $SMTPFrom = “”,
      [Parameter(Mandatory = $true)]
      [string] $SMTPTo = “”,
      [Parameter(Mandatory = $true)]
      [string] $exportpath = “”
      )

      #######
      #
      # HTML Formatting Section
      # Thanks to Paul Cunningham at http://exchangeserverpro.com/
      #
      #######
      #
      #
      #
      ######
      $style = “BODY{font-family: Arial; font-size: 10pt;}”
      $style = $style + “TABLE{border: 1px solid black; border-collapse: collapse;}”
      $style = $style + “TH{border: 1px solid black; background: #dddddd; padding: 5px; }”
      $style = $style + “TD{border: 1px solid black; padding: 5px; }”
      $style = $style + “”

      $messageSubject = “ActiveSync Device Report”

      $message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
      $message.Subject = $messageSubject
      $message.IsBodyHTML = $true

      #### Get Mailbox

      $EASDevices = “”
      $AllEASDevices = @()

      $EASDevices = “”| select ‘User’,’PrimarySMTPAddress’,’DeviceType’,’DeviceModel’,’DeviceOS’,

      ‘LastSyncAttemptTime’,’LastSuccessSync’,‘Guid’
      $EasMailboxes = Get-Mailbox -ResultSize unlimited
      foreach ($EASUser in $EasMailboxes) {
      $EASDevices.user = $EASUser.displayname
      $EASDevices.PrimarySMTPAddress = $EASUser.PrimarySMTPAddress.tostring()
      foreach ($EASUserDevices in Get-ActiveSyncDevice -Mailbox $EasUser.alias) {
      $EASDeviceStatistics = $EASUserDevices | Get-ActiveSyncDeviceStatistics
      $EASDevices.devicetype = $EASUserDevices.devicetype
      $EASDevices.devicemodel = $EASUserDevices.devicemodel
      $EASDevices.deviceos = $EASUserDevices.deviceos
      $EASDevices.lastsyncattempttime = $EASDeviceStatistics.lastsyncattempttime
      $EASDevices.lastsuccesssync = $EASDeviceStatistics.lastsuccesssync
      $EASDevices.guid = $EASDeviceStatistics.guid
      $AllEASDevices += $EASDevices | select

      user,primarysmtpaddress,devicetype,devicemodel,deviceos,lastsyncattempttime,lastsuccesssync,guid
      }
      }
      $AllEASDevices = $AllEASDevices | sort user
      $AllEASDevices
      $AllEASDevices | Export-Csv $exportpath\ActiveSyncReport.csv

      Reply
  33. Tom

    In addition to IMEI, is it also possible to find the device’s MAC address?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>