Thursday, 6 October 2016
The code I put together focuses around using the get-mobiledevice commandlet rather than the older and eventually slated to be decommissioned get-activesyncdevice commandlet. I also added the export-csv commandlet to give me some output I could easily load into excel. If I put some extra work into it, I could make a native export to Excel, but I was doing a quick and dirty dump of the data.
To kick things off, we need to connect to Office365 so the following code I copied intact from TechNet: https://technet.microsoft.com/library/jj984289(v=exchg.160).aspx
*Make sure to open the PowerShell ISE or shell as an administrator.
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
You should be prompted with a login prompt to connect with your Office365 credentials at this point. The next line is where I pull out specific information about what is connected to ActiveSync.
get-mobiledevice | select deviceid,mobileoperator,id,deviceos,deviceimei,DeviceTelephoneNumber | export-csv C:\Activesync.csv
In the end, I make sure to disconnect my session if I decide to do further work with a different tenant.
I've added a link over here to the full script if you want to download and modify it to suit your needs.
Make sure to test out the get-mobiledevice commandlet as it can give you a wide range of device information such as: