How to Connect PowerShell to Office 365

Required Tools

In order for you to manage your Office 365 account, you will need to download and install a few tools. You can manage your account from any Windows PC, you don’t need to install them to a server so can manage accounts directly from your PC or laptop.

Download and install each of the following tools:

Microsoft Online Services Sign-in Assistant


Azure Active Directory Module


SharePoint Online Module


Skype for Business Online Module


Once everything is installed open up Windows PowerShell from the start menu and run it as administrator.

Connect PowerShell to Office 365 1

The PowerShell window opens up and we’re in business!

Connect PowerShell to Office 365 2

Connecting to Office 365

When you start out you only need three commands to connect to the 365 portal. The first will prompt you for the login details of a global administrator and save them into the $credential variable, the second will import the basic 365 PowerShell commands and the third will connect you up using the saved login credentials.

$credential = Get-Credential

Connect PowerShell to Office 365 3

Import-Module MSOnline

Connect-MsolService -Credential $credential

Connect PowerShell to Office 365 4

Next you will need to update the PowerShell Execution policy so that some of the commands will run correctly. The following commands will allow you to run remote signed scripts.

Set-ExecutionPolicy “RemoteSigned” -Scope Process -Confirm:$false

Set-ExecutionPolicy “RemoteSigned” -Scope CurrentUser -Confirm:$false

If you want to manage Skype for Business Online, you will need to import the Lync Online module and import the session.

Import-Module LyncOnlineConnector

$session = New-CsOnlineSession -Credential $credential

Import-PSSession $session

Connect PowerShell to Office 365 5

If you want to manage SharePoint you will need to run the following:

Import-Module Microsoft.Online.Sharepoint.PowerShell

Connect-SPOService -url https://office365laba-admin.sharepoint.com -Credential $credential

Connect PowerShell to Office 365 6

And finally if you want to manage Exchange online you will need to run the following to create and import an Exchange session.

$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri “https://outlook.office365.com/powershell-liveid/” -Credential $credential -Authentication “Basic” –AllowRedirection

Import-PSSession $session

Connect PowerShell to Office 365 7

Once you have all of the modules loaded you can list all of the available commands by running: Get-Command it’s a good idea to browse over the available commands and familiarize yourself with them. There have been plenty of times where I’ve seen a command that looks interesting and then I go on to use it in a script.

Connect PowerShell to Office 365 8


Connecting PowerShell to Office 365 is relatively straight forward and opens up lots of new opportunities. If you work with Office 365 as part of your job then learning to use PowerShell is a great way to get ahead of your peers and make your life easier. Follow the blog to get lots of helpful tips on managing Office 365 using PowerShell, its what I do every day so there should be something for everyone.

[email-download download_id=”9801″ contact_form_id=”9351″]

If you want to get stuck in then you can buy my book from Amazon either the paper back or kindle version. My advice is to buy the paperback version so you can keep it on your desk for easy reference!

Office 365 PowerShell Book

For paperback version click here

For Kindle version click here

Author: Ian@SlashAdmin

Share This Post On
468 ad


  1. Hi,

    I noticed you are using the older MSOnline PowerShell module in your examples. It may be useful to start using the newer Azure Active Directory PowerShell V2 module instead, as we will begin deprecating the MSOnline module when we have migrated the functionality of the MSOnline module to the newer module – currently planned for the Spring of 2017.


    Rob de Jong

    Post a Reply
  2. Thanks Rob!

    I’ll definitely update the examples here asap.

    Thanks for stopping by 🙂

    Post a Reply
  3. Have you ever updated the examples?
    I started following and found that Import-Module MSOnline no longer works.

    Post a Reply

Leave a Reply to Bob Bell Cancel reply

Your email address will not be published.