Connect to Office 365 via Powershell

Background

Most administration of Office 365 is done using the Office 365 Admin Center (https://portal.office.com/admin) eg license assignment, domain management, email maintenance (via Exchange Admin Center link) etc.

Administering Exchange via Powershell is still possible however there are extra steps involved due to increased security required in accessing cloud resources.

Below are the prerequisites and steps to connect to Office 365 via Powershell

Prerequisites

  • Windows 8, 10 or 2012/R2
  • Microsoft.NET Framework 4.5 or later

Steps

1. On your local computer, open Windows Powershell (as local administrator) and run the following command.

$UserCredential = Get-Credential

In the Windows PowerShell Credential Request dialog box, type your Office 365 user name (eg admin@<tenant name>.onmicrosoft.com) and password and then click OK.

2. Run the following command.

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

3. Run the following command.

Import-PSSession $Session

4. You are now ready to enter your Powershell cmdlets,

eg:
Get-MailboxStatistics joe.bloggs | ft DisplayName, TotalItemSize, ItemCount

5. (Important) When finished do not just click the top right X. Instead disconnect the remote Powershell session properly by running the command below.

Remove-PSSession $Session
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s