---
title: "Connect PowerShell to Office 365: Step-by-Step Tutorial"
description: "Effortlessly connect PowerShell to Office 365 with this step-by-step tutorial. Manage your Office 365 environment with ease."
canonical: "https://adamtheautomator.com/how-to-connect-powershell-to-office-365/"
---

# Connect PowerShell to Office 365: Step-by-Step Tutorial

> Effortlessly connect PowerShell to Office 365 with this step-by-step tutorial. Manage your Office 365 environment with ease.

Source: https://adamtheautomator.com/how-to-connect-powershell-to-office-365/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Connect PowerShell to Office 365: Step-by-Step Tutorial](https://adamtheautomator.com/wp-content/uploads/2019/07/photo-1504270997636-07ddfbd48945.jpg)

# Connect PowerShell to Office 365: Step-by-Step Tutorial

[![](https://secure.gravatar.com/avatar/5cd71a4e2894e3d2608b9e07347e05b85fa86e0955eb3f708412e6b9da7fd920?s=192&d=mm&r=g)Faris Malaeb](https://adamtheautomator.com/author/faris/)2 February 20214 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Office 365](/tag/office-365/)[PowerShell](/tag/powershell/)

Table of Contents

*   [Prerequisites](#h-prerequisites)
*   [Using PowerShell to connect to office 365](#using-powershell-to-connect-to-office-365)
*   [Downloading and installing Office 365 PowerShell Module](#downloading-and-installing-office-365-powershell-module)
*   [Connect PowerShell to Office 365 Services](#connect-powershell-to-office-365-services)
*   [Why Two Azure AD Modules?](#why-two-azure-ad-modules)
*   [Using PowerShell to Connect to multiple Office 365 Service](#using-powershell-to-connect-to-multiple-office-365-service)
*   [Summary](#summary)

Connecting to Office 365 with PowerShell can be a pain sometimes. You have to constantly remember different commands __and__ modules. Let’s change that.

Not a reader? Watch this related video tutorial!

**_Not seeing the video? Make sure your ad blocker is disabled._**

In this article, you’ll learn how to connect PowerShell to Office 365. You’ll do this by using the Azure AD PowerShell for Graph module and the Azure [Active Directory module](https://adamtheautomator.com/powershell-import-active-directory/ "Active Directory module") for Windows PowerShell.

> _Microsoft 365 Backup For Dummies eBook addresses the data security challenges by outlining the out-of-the-box security features in Microsoft 365. [Get eBook](https://go.veeam.com/office-365-backup-for-dummies?utm_campaign=01BR-M365-GB_Global_EN_0_Custom_WP_dummies-office365&utm_source=adamtheautomator.com&utm_medium=dcm&st=pa&ccode=dcmbloggers)_

## Prerequisites

To run through any of the examples in this tutorial, please be sure you have the following ahead of time:

*   Windows PowerShell 5.1 or PowerShell 7
*   An Office 365 tenant
*   [Microsoft Online Services Sign-In Assistant for IT Professionals RTW](https://www.microsoft.com/en-us/download/details.aspx?id=28177)

> You can download PowerShell 7 from the [Microsoft website](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.1)

## Using PowerShell to connect to office 365

Office 365 includes an abroad range of services that include and are not limited to:

*   Azure Active Directory.
*   Exchange Online.
*   Microsoft Teams.

Office 365 services are all available via a common landing web portal called [](https://portal.microsoft.com/)[https://portal.microsoft.com](https://portal.microsoft.com). This portal gives you access to domain setup, Tenant configuration, billing, and managing user’s settings. But if you need to go to Office 365 services, such as Exchange Online or Microsoft Teams, you need to click on the service name in the portal which will take you to the service admin center, such as Exchange Admin Center, and so on.

Each service has its own admin center portal and PowerShell module. So if you need to connect to manage users on Exchange Online, you need to download the Exchange online PowerShell module. If you want to manage users on Teams, you need to download the Teams module and also for the Azure active directory PowerShell module.

## Downloading and installing Office 365 PowerShell Module

An easy approach is to use PowerShell itself to find, download and install the PowerShell module. Let’s try to get the Exchange Online PowerShell module. Start by opening PowerShell and type the following PowerShell command line to find the available modules related to Exchange online.

```powershell
Find-Module Exchangeonline*
```

![https://www.powershellcenter.com/wp-content/uploads/2021/11/image-2.png](https://www.powershellcenter.com/wp-content/uploads/2021/11/image-2.png)

Fiding PowerShell Module

> You can use a wildcard to search for all related PowerShell Module

Using the `Find-Module` helps in searching for a module in the PowerShell gallery, you might find multiple PowerShell modules. The one we are looking for is **ExchangeOnlineManagement**. To download and install the module, use the `install-module` cmdlet

If no error returns, then you are good to go and start using the module. The next step is to start using the module

> Since PowerShell 3, PowerShell can import the module automatically the first time you run any command related to the installed module.

The same method of downloading the module is applicable to any other module, all you need is to know the module name and download it.

## Connect PowerShell to Office 365 Services

Each Office 365 has its own PowerShell module, this makes cross services management a bit challenging. Usually, any Office 365 module has a similar cmdlet `Connect-*ServiceName*`

*   Connect to Exchange Online, you can use the cmdlet `Connect-ExchangeOnline` which is available in **ExchangeOnlineManagement** Module
*   Connect to Microsoft Teams use the following cmdlet `Connect-MicrosoftTeams` which is available in **MicrosoftTeams** Module
*   To connect to Azure AD using Azure AD PowerShell for Graph, use `Connect-AzureAD` which is available in the **AzureAD** Module
*   Connect to Sharepoint Online, use `Connect-PnPOnline` which is available in the **Microsoft.Online.SharePoint.PowerShell** Module.
*   Connect to Azure AD for Windows PowerShell module, use `Connect-MsolService` which is available in **MSOnline** Module

> PowerShell Core doesn’t support the Azure AD for Windows PowerShell module and cmdlets with _Msol_ in their name.

## Why Two Azure AD Modules?

When working with Office 365 using PowerShell, you’ll probably have to use two different modules. You’ll use __[Azure Active Directory PowerShell for Graph](https://docs.microsoft.com/en-us/powershell/azure/active-directory/ad-pshell-v2-version-history)__ with the module name __AzureAD__ and __Azure Active Directory Module for Windows PowerShell__ with the module name of __[MSOnline](https://docs.microsoft.com/en-us/powershell/module/msonline/).__

__AzureAD__ and __MSOnline__ both allow you to work with Office 365 services using PowerShell so why two? __AzureAD__ is the successor to __MSOnline__ and from what I can gather will replace __MSOnline__ at some point. All new functionality is in the __AzureAD__ module but there still is some overlap with the __MSOnline__ module.

You’ll find tasks such as managing users, groups, and license administration still exists in the __MSOnline__ module.

> _If you need to connect to Exchange Online via MFA, Microsoft provides a great guide entitled [Connect to Exchange Online PowerShell Using Multi-Factor Authentication](https://docs.microsoft.com/en-us/powershell/exchange/exchange-online/connect-to-exchange-online-powershell/mfa-connect-to-exchange-online-powershell?view=exchange-ps)._

## Using PowerShell to Connect to multiple Office 365 Service

Office 365 PowerShell modules look like a big list, yes?!. But it’s possible to connect to all the services in one console and then do all the tasks in the same console by using the following PowerShell code.

```powershell
$CloudCred=Get-Credential
$TenantName="Test for test.onmicrosoft.com"
Connect-AzureAD -Credential $CloudCred
Connect-PnPOnline -Url https://$TenantName.sharepoint.com -Credentials $CloudCred
Connect-ExchangeOnline -Credential $CloudCred
Connect-MicrosoftTeams -Credential $CloudCred
```

You might get the following error when connecting to Sharepoint

_Connect-PnPOnline : AADSTS65001: The user or administrator has not consented to use the application with ID ‘31359c7f-bd7e-8888-86db-fdb8c937548e’ named ‘PnP Management Shell’. Send an interactive authorization request for this user and resource.Trace ID: b9913a0b-b47d-4ffe-bdc7-70ed81143000_

To fix this issue, run the `Register-PnPManagementShellAccess` cmdlet, type the username and password and then make sure to check the “**Consent on behalf of your organization**“

![Connect PowerShell to Office 354](https://www.powershellcenter.com/wp-content/uploads/2021/11/image-3.png)

**Consent on behalf of your organization**

Always make sure that your modules are up-to-date, as new features and compatibility are added frequently, most of the Office 365 PowerShell modules now supports Multi-Factor Authentication

> _Microsoft 365 Backup For Dummies eBook addresses the data security challenges by outlining the out-of-the-box security features in Microsoft 365. [Get eBook](https://go.veeam.com/office-365-backup-for-dummies?utm_campaign=01BR-M365-GB_Global_EN_0_Custom_WP_dummies-office365&utm_source=adamtheautomator.com&utm_medium=dcm&st=pa&ccode=dcmbloggers)_

## Summary

Office 365 has many services but fortunately, you can manage them all with PowerShell. Once you’ve installed both modules and connected using the `Connect` commands, you are on your way to managing Office 365 with PowerShell!

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fhow-to-connect-powershell-to-office-365%2F&text=Connect%20PowerShell%20to%20Office%20365%3A%20Step-by-Step%20Tutorial)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fhow-to-connect-powershell-to-office-365%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fhow-to-connect-powershell-to-office-365%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2020/07/New-Exchange-Online-V2-PowerShell-Module.png)

### [Connect to Exchange Online PowerShell with EXO V2 Module](/exchange-online-v2/)

Learn how to connect to Exchange Online via PowerShell using the EXO V2 module for unattended, app-only authentication.

![](https://adamtheautomator.com/wp-content/uploads/2026/06/26995-troubleshoot-dns-issues-powershell-codex.webp)

### [Troubleshoot DNS Issues with PowerShell](/troubleshoot-dns-issues-powershell/)

Troubleshoot DNS issues with PowerShell by testing name resolution, DNS client settings, cache entries, and network connectivity in a repeatable workflow.

![](https://adamtheautomator.com/wp-content/uploads/2025/10/image_2025-10-24_095322075.png)

### [Migrating from PowerShell 6 to 7.5: Breaking Changes/New Features](/migrating-powershell-6-to-7-5/)

Migrate from PowerShell Core 6 to 7.5: breaking changes, features, and testing tips.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
