Powershell Office 365: Building a Hash Table and a Custom PSObject to Get-UserInfo

Here is a script that will quickly tell you some mailbox information and some mailbox statistics for an Exchange Online such as Office 365 mailbox. This will also work with Exchange Shell on Exchange 2013 on Premises.

The data is collated from 2 different cmdlets, Get-MsolUser and Get-MailboxStatistics. The data is then used to create an advanced function called Get-UserInfo.

This post serves as a demonstration in building a hash table and a custom PSObject, one of the most important aspects of PowerShell scripting. It also serves to demonstrate the principal of gathering output from various cmdlets and bringing them together as one.

It has been assumed that you have installed the PowerShell Module called MSOnline and authenticated to Office 365 via PowerShell in the usual way.

If you were to "Dot Source" the script using PowerShell.exe then you would run it with the following :

Get-UserInfo -UPN user@mail.com -Verbose -ErrorLog

This script example will only support one UserPrincipalName input although can be easily changed to accept multiple, CSV input and accross the pipeline if required. This is outwith the scope of this post.

Read More