Remote Access to Office 365 Via Powershell

bogart-maltese-falcon
In an on-premise Exchange environment, your PowerShell connection to the server is essentially a remote session (even though it occurs within your Kerberos-enclosed domain).  In an Exchange 2010 environment the EMC (when installed on a Windows desktop) obscures this relationship but it’s there nonetheless.

It’s no different when you connect to Office 365 for PowerShell administration (which is, as I’ve stated before, the best and most powerful way to manage your Exchange tenant).

The how-to is basic and covered well by Microsoft here and at Tom’s IT Pro here.

Briefly, the syntax is very simple:

$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Set-ExecutionPolicy RemoteSigned
Import-PSSession $Session

In which, an object named $UserCredential is created that employs the get-credential cmdlet to gather your, well, credentials and passes that to Office365’s web service (for PowerShell).

The session data is imported so the cmdlet set appropriate for Office365 is imported.  This includes familiar tools such as get-mailbox.

When finished, you end your session by invoking Remove-session $Session which cleans up your PowerShell threads of execution (preventing orphaned sessions).

 

Published by

D. Roberto

No one can know everything...but I come close! Actually, this project is an enhanced version of the notes I take everyday to sharpen my skills and deepen my understanding. Hopefully, it can be of some benefit to my fellow specialists around the world.