PowerShell script to find users with OWA and Mobile App enabled – Office 365

I was tasked to create a PowerShell script to quickly find out how many users have OWA enabled and how many have Mobile App (ActiveSync) enabled. Complicating this was the deployment is on Office 365/Exchange 365 setup. Following is the end result of the endeavor which will quickly give you the list you want.

# Created by Asanka Gunasekara - 2/14/2020
# This script generates list of users who has OWA enabled and Mobile/Active Sync Enabled.
# User needs special permission: https://docs.microsoft.com/en-us/exchange/troubleshoot/connecting-to-the-service/access-denied-connect-powershell
# User needs to enter their full username: [email protected]

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

Write-Output ""
Write-Output "Users with OWA Enabled"
Get-CASMailbox -ResultSize Unlimited | where { $_.OWAEnabled } | sort DisplayName | ft DisplayName, PrimarySmtpAddress, OWAEnabled –autosize
Write-Output "Users with Mobile APP Enabled"
Get-CASMailbox -ResultSize Unlimited | where { $_.ActiveSyncEnabled} | sort DisplayName | ft DisplayName, PrimarySmtpAddress, activesyncenabled –autosize

Remove-PSSession $Session