The other day I was working on some PowerShell scripts to manage shared mailboxes in O365. If you are familiar with this you obviously know that you need to setup a connection with Exchange online first. This will look something like this:
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $credential -Authentication Basic -AllowRedirection
Import-PSSession $session -DisableNameChecking
When you do this, it will always output something like this (to show what commands are imported into your session):
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 1.0 tmp_32cirzmw.zex {Add-AvailabilityAddressSpace, ...}
Surely after testing your scripts a thousand times, chances are little you’re still interested in this output. I found this neat little trick on Stackoverflow to suppress it:
$null = Import-PSSession $session -DisableNameChecking
By adding the first part the output is omitted. When you use scripts connecting to O365 to fill list controls in our dynamic forms you must apply this, otherwise your lists will stay empty, because Provisior will use that output for filling which is obviously not what you want.
One extra tip at the end. If you only use a couple of commands you can specify them when setting up the session. This will speed up your script dramatically!
$null = Import-PSSession $session -DisableNameChecking -CommandName Get-Mailbox, Set-Mailbox