My Articles Support Center

Contact Us

Connect to Office 365 PowerShell

Summary: Connect to your Office 365 organization using Office 365 PowerShell to perform Office 365 administration tasks from the command line.

Office 365 PowerShell lets you to manage your Office 365 settings from the command line. Connecting to Office 365 PowerShell is a simple three-step process where you install the required software, run the required software, and then connect to your Office 365 organization.

What do you need to know before you begin?

Connect with the Microsoft Azure Active Directory Module for Windows PowerShell

Commands in the Microsoft Azure Active Directory Module for Windows PowerShell have Msol in their cmdlet name.

Step 1: Install required software

These steps are required once on your computer, not every time you connect. However, you'll likely need to install newer versions of the software periodically.

  1. Install the 64-bit version of the Microsoft Online Services Sign-in Assistant: Microsoft Online Services Sign-in Assistant for IT Professionals RTW.
  2. Install the the Microsoft Azure Active Directory Module for Windows PowerShell with these steps:
    • Open an administrator-level PowerShell command prompt.
    • Run the Install-Module MSOnline command.
    • If prompted to install the NuGet provider, type Y and press ENTER.
    • If prompted to install the module from PSGallery, type Y and press ENTER.
    • After installation, close the PowerShell command window.

Step 2: Connect to your Office 365 subscription


To connect with just an account name and password:

Run this command

Set-ExecutionPolicy Unrestricted
  1. Run a Windows PowerShell command prompt.
  2. In the Windows PowerShell command window, run the following commands:
$UserCredential = Get-Credential
Connect-MsolService -Credential $UserCredential
  1. In the Windows PowerShell Credential Request dialog box, type your Office 365 work or school account user name and password, and then click OK.
  2. To connect with multi-factor authentication (MFA):
    1. Run a Windows PowerShell command prompt.
    2. In the Microsoft Azure Active Directory Module for Windows PowerShell command window, run the following command.
      Connect-MsolService
    3. In the Azure Active Directory PowerShell dialog box, type your Office 365 work or school account user name and password, and then click Sign in.
    4. Follow the instructions in the Azure Active Directory PowerShell dialog box to provide additional authentication information, such as a verification code, and then click Sign in.

Here are all the commands in a single block. Specify the name of your domain host, and then run them all at one time.

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

How do you know this worked?

If you don't receive any errors, you connected successfully. A quick test is to run an Office 365 cmdlet—for example, Get-MsolUser —and see the results.

Powered by HelpSite