Find devices attached to Microsoft 365 mail accounts
I was recently asked if there was a way to see a list of users who had mobile devices attached to their Microsoft 365 or Office 365 account. In order to do this I have written a PowerShell script.
The script is generic only relies on you having global admin access to Office 365. Built into my script is the commands that prompts for your Office 365 admin credentials and connects your PowerShell session to your tenant. The script builds and output file called MobileDevices.csv and stores that file in the root of the C drive.
If you wish you can change that location by modifying this section of the script. The next stage in the script is to search your tenant for all mailboxes within your tenant and store them within the mailboxes variable.
Once the script has the information relating to the mailboxes it then starts to search through the list and identifies which mailboxes have a mobile device attached. This uses the new Get-MobileDeviceStatistics, which is replacing the traditional Get-ActiveSyncDeviceStatistics cmdlet that you may be more familiar with.
The script loops round and appends any information that it finds into the output file for each user and their device, or devices. Download the script from the GitHub
If you've used this script in your environment I'd love to hear from you, please leave a comment here or contact me via Twitter - @TechieLass