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.

Here is the script:

Alan

 

Related Post

PowerShell SharePoint PnP: Installing SharePoint P... Open Windows Powershell as Administrator. Run the following Install-Module SharepointPNPPowershellOnline Type A when prompted. To veri...
Call Office 365 Service Communications API and Ret... In part 5, we will now look to create the flow that will populate the nested folder called O365 Notices. More information on the folder structure in p...
PowerShell Office 365: SMTP Email Sent with PowerS... In this example, I have an extremely simple function called MyCode. The purpose of the function is only to demonstrate us taking any PowerShell output...
Create Office 365 Alerts Shared Mailbox from APIs ... In terms of Office 365, when trying keep your eye on AAD Connect synchronisation, new Service Health notices, new O365 Endpoints, new Message Center u...