Contents

Connect to Office 365 using PowerShell


Contents

In order to manage your Office 365 tenant(s) using PowerShell, there are some pre-requisites required.

  1. Ensure you are running Windows 8.1, Windows 8, or Windows 7.
  2. Make sure you have the .NET Framework 3.51 feature [enabled by default on Windows 8 and up]
  3. Make sure you have the latest updates. It is important to run this after you install .NET Framework 3.51, so you get updates for that in addition to updates for your operating system.
  4. Install the Microsoft Online Services Sign-In assistant. Even though the link provided should work, you should always look up the latest version [see next link].
  5. Install the Windows Azure Active Directory (Azure AD) module for the appropriate version of your operating system.

Once these requirements are installed, you can continue to connect to your tenant using the following function:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
Function Connect-O365 {

Param (
  [Parameter(Mandatory=$true)]
  $User
  )

  $Cred = Get-Credential -Credential $User

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

  Import-Module (Import-PSSession $Session -AllowClobber) -Global

  Connect-MSOLService -Credential $Cred

}

This will set up a connection with your Office 365 tenant and will also connect to the Exchange configuration so you can easily access mail configuration for your tenant.

Happy scripting!