Monday 10 November 2014

Connecting to Office365 using PowerShell for Remote Management

You can using PowerShell from an on-premise server to manage an instance of Office365 in Microsoft's cloud. It can be useful to manage more of the complex Exchange, Lync and SharePoint configuration settings that are available.

Firstly open an Administrative PowerShell box, I did this from Windows Server 2012 R2 copy and paste the following command into the PowerShell window.

$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://ps.outlook.com/powershell/" -Credential $cred -Authentication Basic -AllowRedirection

This will invoke a credentials window that you must enter the Global Administrator account for the Office365 subscription. It should be in the format username@domain with the corresponding password.


The next command is the following to create a new session;

Import-PSSession $session


Once this command has completed you can use the following two PowerShell commands to create to see what commands are available in the Office365 PowerShell module that has been imported.

Get-Module ModuleName

Get-Command –Module ModuleName


To confirm it is working I did a Get-Mailbox and PowerShell returned a list of all of the Office365 mailboxes active on the subscription.