Connect to Office 365 PowerShell

 

Applies to: Office 365 Enterprise, Office 365 Midsize Business, Office 365 Small Business

Topic Last Modified: 2017-05-31

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

Office 365 PowerShell lets you to manage your Office 365 admin center 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. Note that these connection instructions are the same as those in the topic Manage Azure AD using Windows PowerShell.

  • Estimated time to complete: 5 minutes

  • You can use the following versions of Windows:

    • Windows 10, Windows 8.1, Windows 8 or Windows 7 Service Pack 1 (SP1)

    • Windows Server 2012 R2, Windows Server 2012, or Windows Server 2008 R2 SP1

    Note

    Use a 64-bit version of Windows. Support for the 32-bit version the Windows Azure Active Directory Module for Windows PowerShell was discontinued in October, 2014.

  • The Office 365 work or school account that you use for these procedures needs to be a member of the Office 365 Global admin role. For more information about permissions in Windows Azure Active Directory Module for Windows PowerShell Office 365, see Permissions in Office 365.

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 64-bit version of the Windows Azure Active Directory Module for Windows PowerShell with these steps:

    • Open the Azure Active Directory Connection web page.

    • In Files in Download at the bottom of the page, click Download for the AdministrationConfig-V1.1.166.0-GA.msi file, and then install it.

  1. Find and open the Windows Azure Active Directory Module for Windows PowerShell by using one of the following methods based on your version of Windows:

    • Start menu   On the Start menu, enter Azure in the Search programs and files box.

    • No Start menu   Search for Azure using any of these methods:

      • On the Start screen, click an empty area, and type Azure.

      • On the desktop or the Start screen, press the Windows key+Q. In the Search charm, type Azure.

      • On the desktop or the Start screen, move your cursor to the upper-right corner, or swipe left from the right edge of the screen to show the charms. Select the Search charm, and enter Azure.

  2. In the results, select Windows Azure Active Directory Module for Windows PowerShell.

To connect with just an account name and password:

  1. In the Windows Azure Active Directory Module for Windows PowerShell, run the following commands.

    $UserCredential = Get-Credential
    Connect-MsolService -Credential $UserCredential
    
  2. In the Windows PowerShell Credential Request dialog box, type your Office 365 work or school account user name and password, and then click OK.

To connect with multi-factor authentication (MFA):

  1. In the Windows Azure Active Directory Module for Windows PowerShell, run the following command.

    Connect-MsolService
    
  2. 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.

  3. 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.

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.

If you receive errors, check the following requirements:

  • A common problem is an incorrect password. Run Step 3 again. and pay close attention to the user name and password you enter.

  • The Windows Azure Active Directory Module for Windows PowerShell requires that the Microsoft .NET Framework 3.5.x feature is enabled on your computer. It's likely that your computer has a newer version installed (for example, 4 or 4.5.x), but backwards compatibility with older versions of the .NET Framework can be enabled or disabled. For more information, see the following topics:

  • Your version of the Windows Azure Active Directory Module for Windows PowerShell might be out of date. To check, run the following command in Office 365 PowerShell or the Windows Azure Active Directory Module for Windows PowerShell:

    (Get-Item C:\Windows\System32\WindowsPowerShell\v1.0\Modules\MSOnline\Microsoft.Online.Administration.Automation.PSModule.dll).VersionInfo.FileVersion
    

    If the version number returned is lower than the value 1.0.8070.2, uninstall the Windows Azure Active Directory Module for Windows PowerShell, and install the latest version from the link in Step 1.

  • If you receive a connection error, see this topic: "Connect-MsolService: Exception of type was thrown" error.

For procedures that require the new cmdlets in the Azure Active Directory V2 PowerShell module, use these steps to install the module and connect to your Office 365 subscription:

  1. Open an elevated Windows PowerShell command prompt.

  2. Run this command:

    Install-Module -Name AzureAD 
    

    If prompted to install a NuGet module or the new Azure Active Directory V2 PowerShell module, type Y and press ENTER.

  3. When the installation of the new module is complete:

    • Use these commands to connect to your Office 365 subscription with an account name and password:

      $UserCredential = Get-Credential
      Connect-AzureAD -Credential $UserCredential
      

      In the Windows PowerShell Credential Request dialog box, type your Office 365 work or school account user name and password, and then click OK.

    • Use these commands to connect to your Office 365 subscription with multi-factor authentication (MFA):

      Connect-AzureAD
      

      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.

      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.

After connecting, you can use the new cmdlets for the Azure Active Directory V2 PowerShell module.

 
Show: