SharePoint Online

How to connect PowerShell with Office 365

Installation of Azure Active Directory Module

Before you start connecting PowerShell with Office 365 you must be sure to have the Azure Active Directory Module installed on your computer. This Azure Active Directory Module support your Windows PowerShell module with the needed cmdlets to connect to Office 365.

For getting the cmdlet of Azure Active Directory you have two possibilities. You can download Azure Active Directory Module V1 and install this software or you can install Azure Active Directory Module V2 directly in PowerShell from NuGet. Until now the 2nd possibility was not working for me on Windows 7 behind a proxy in the company.

Azure Active Directory Module V1

  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.

Azure Active Directory Module V2 from NuGet

  1. Open the Windows PowerShell as Administrator and run the following command:
    Install-Module -Name AzureAD
  2. If prompted to install a NuGet module or the new Azure Active Directory V2 PowerShell module, type Y and press ENTER.

Establish the connection to Office 365

Using user name and password for Office 365 account

  1. Please fill in the variable $userName. After you have filled the variable you can run this commands:
    $userName = <the email address of a SharePoint Online / Global Administrator>
    $userCred = Get-Credential -UserName $userName -Message "Credentials for Office 365"
    Connect-MsolService -Credential $userCred
  2. By running the 2nd command line you will getting a dialog box for entering the password. The user name is already typed in because of setting the variable. Please type in the password of the chosen user.
  3. You are now connected to Office 365 of your tenant and you can start with executing your commands.

Multifactor authentication for Office 365 account

  1. Please run the following command to connect to Office 365:
    Connect-MsolService
  2. By running this command you will get the dialog box for typing in your user name and password. Please type in the credentials of an Office 365 account, and then click Sign in.
  3. Follow the instruction of the dialog box to add the additional authentication information.
  4. You are now connected to Office 365 of your tenant and you can start with executing your commands.

Reference

0 Kommentare zu “How to connect PowerShell with Office 365

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

%d Bloggern gefällt das: