PowerShell scripts for Microsoft 365

Your download is in progress and it will be complete in just a few seconds! If you face any issues, download manually here

Thank you for registering with ManageEngine.

We will send the download link to the registered email ID shortly.

Manage and Secure Microsoft 365 with M365 Manager Plus

  • By clicking 'Download 30-day free trial' you agree to processing of personal data according to the Privacy Policy.

PowerShell script to fetch ActiveSync statistics for Microsoft 365 mailboxes

The Microsoft 365 Admin Center doesn’t provide complete information about ActiveSync-enabled mobile devices. This is the reason most IT admins rely on PowerShell scripts to obtain the in-depth details they require. But the process can involve cumbersome code. As an example, below are the PowerShell scripts needed to acquire ActiveSync statistics.

Step 1: Connecting to Exchange Online

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session

This PowerShell cmdlet imports the Exchange Online cmdlets to the local Windows PowerShell session.

Step 2: Retrieving all mailboxes

$mailboxes = Get-Mailbox -ResultSize unlimited

This PowerShell cmdlet fetches all mailboxes in the organization.

Step 3: Filtering the output.

foreach ($mailbox in $mailboxes)
$devices = Get-ActiveSyncDeviceStatistics -Mailbox $mailbox.samaccountname
if ($devices) {
foreach ($device in $devices){
$deviceobj = New-Object -TypeName psobject
$deviceobj | Add-Member -Name DisplayName -Value $mailbox.DisplayName -MemberType NoteProperty
$deviceobj | Add-Member -Name UPN -Value $mailbox.UserPrincipalName -MemberType NoteProperty
$deviceobj | Add-Member -Name Status -Value $device.Status -MemberType NoteProperty
$deviceobj | Add-Member -Name DeviceID -Value $device.DeviceID -MemberType NoteProperty
$deviceobj | Add-Member -Name DeviceEnableOutboundSMS -Value $device.DeviceEnableOutboundSMS -MemberType NoteProperty
$deviceobj | Add-Member -Name DeviceMobileOperator -Value $device.DeviceMobileOperator -MemberType NoteProperty
$deviceobj | Add-Member -Name DeviceAccessState -Value $device.DeviceAccessState -MemberType NoteProperty
$deviceobj | Add-Member -Name DeviceActiveSyncVersion -Value $device.DeviceActiveSyncVersion -MemberType NoteProperty
$deviceobj | Add-Member -Name FirstSyncTime -Value ($device.FirstSyncTime).ToString("yyyy-MM-dd HH:mm:ss") -MemberType NoteProperty
$deviceobj | Add-Member -Name LastPolicyUpdateTime -Value ($device.LastPolicyUpdateTime).ToString("yyyy-MM-dd HH:mm:ss") -MemberType NoteProperty
$deviceobj | Add-Member -Name LastSyncAttemptTime -Value ($device.LastSyncAttemptTime).ToString("yyyy-MM-dd HH:mm:ss") -MemberType NoteProperty
$deviceobj | Add-Member -Name LastSuccessSync -Value ($device.LastSuccessSync).ToString("yyyy-MM-dd HH:mm:ss") -MemberType NoteProperty
$deviceobj | Add-Member -Name NumberOfFoldersSynced -Value $device.NumberOfFoldersSynced -MemberType NoteProperty

This code fetches the mailboxes' ActiveSync connected devices, and shows the associated username, display name, email address, number of devices each user has, and more. The results are then exported to a CSV file.

M365 Manager Plus' preconfigured ActiveSync reports to the rescue

IT admins are often overwhelmed by the sheer volume of the Excel spreadsheets or CSV files generated to micromanage each device configured with Microsoft 365. But there is a more efficient process.

M365 Manager Plus, ManageEngine’s Microsoft 365 reporting, auditing, monitoring, and management tool, comes with more than 700 preconfigured reports on Azure AD, Exchange Online, Skype for Business, OneDrive for Business, Yammer, and other Microsoft 365 services. These can assist IT admins in effortlessly monitoring users and mailboxes in bulk.

M365 Manager Plus' mobile device reports help IT admins keep track of all the Microsoft 365 ActiveSync-enabled mobile devices by mapping users' mobile devices with their corresponding Microsoft 365 mailboxes and policies. The reports can be scheduled to run at fixed intervals, emailed to administrators, and exported to CSV, XLSX, PDF, or HTML formats.

Some of M365 Manager Plus' reports for fetching ActiveSync statistics include:

  • Mobile Devices
  • Mobile Devices by OS
  • Mobile Devices by Policy
  • Mobile Devices by Manufacturer
  • Mobile Devices by Client
  • Active Mobile Devices
  • Device Policy Application Status
  • Folders Synchronized Per Device
  • Device By Access State
  • Inactive ActiveSync Devices
  • ActiveSync Enabled Mailboxes

Advantages of M365 Manager Plus' reporting

Advanced filters: Use attribute and condition-based filters to obtain the data required without running complex PowerShell scripts.

Reports on historical data: PowerShell cmdlets can only retrieve data at least seven days old and no older than 180 days. But M365 Manager Plus’ reports can fetch all data from the date of installation.

Customizable dashboard: M365 Manager Plus’ dashboard is customizable. Add reports in graph formats to take a quick peek at the mail traffic summary, top email senders and receivers, client device usage, and more. This dashboard can be embedded in any of the webpages to enable constant monitoring.

Report scheduler: Schedule reports to be generated at regular intervals to reduce the overhead of generating them manually.

Many export options: Reports can be exported to PDF, XLSX, HTML, or CSV formats, and emailed to administrators.

Secure delegation: Delegate the task of report generation to technicians and IT staff securely, without giving them full access to the Microsoft 365 Admin Center.

Why businesses choose M365 Manager Plus?

What our customers say

  • We can now effectively reconcile which licenses we are using in the organization and assign the cost to the business unit. We were also able to identify a number of license changes that could be put in place that reduced our total Microsoft 365 spending.

    Timothy Ransom
    Group IT/IS manager at The Eclipse Group, United Arab Emirates

  • M365 Manager Plus is valuable to our future business and, most importantly, it allows me to keep improving the level of service we provide.

    IT infrastructure manager
    Sunstar Suisse S.A.

  • Our firm purchased ManageEngine M365 Manager Plus to help us protect our business from email-borne cyberthreats. We are absolutely satisfied with the features and ease of use. It has surpassed our expectations.

    Insurance agent
    Security and risk management Gartner review

A holistic Microsoft 365 administration solution

One-stop solution for all your
Microsoft 365 administration needs!

Download now