How to Connect to Office 365 PowerShell: Azure AD Modules

This post will cover how to connect PowerShell to Office 365 (Azure Active Directory (Azure AD)), which manages Microsoft 365 tenant identities and licenses. I will also cover connecting to other services and products in Microsoft 365, such as Exchange, SharePoint, and Microsoft Teams.

  • Before Connecting

  • How to Connect Powershell to Microsoft 365

  • How to Connect Powershell to Other 365 Platforms

  • Multi-Factor Authentication

Reasons to Connect Powershell

If you have worked with Microsoft technologies in the last decade, you know that PowerShell is the preferred language for managing and configuring many Microsoft products. There are multiple reasons to use PowerShell to manage Microsoft 365:

  • Automation for Productivity: You can perform bulk operations using PowerShell, such as assigning licenses or configuring mailbox settings.

  • Settings Only Configurable with PowerShell: Microsoft can’t put every setting in the admin center, so PowerShell is sometimes the only way to make a configuration change. For examples of settings only configurable through PowerShell, check out 7 Hidden Office 365 Settings You Can Unlock with PowerShell by Vlad Catrinescu.

  • Filtering Data: PowerShell can filter data and provide relevant results, such as mailbox type or a user’s assigned location.

  • Exporting Data: Just as PowerShell can gather and filter data, you can also use it to export data. The most common option is exporting to a CSV file, but you can also format the data into JSON or XML.

  • Management Across Products: Each service has its own set of PowerShell management capabilities. PowerShell can perform operations in each service for onboarding new user accounts or compiling a report of information involving multiple services.

  • Standardization: You can write a script or function in PowerShell to standardize a task, such as creating a new user account or setting up a new SharePoint site. By making the task repeatable, you ensure that the process follows specific procedures each time, which can be missed if performed manually in the admin center.

Before Connecting to Azure AD Powershell

You need to meet some prerequisites before connecting out to Azure AD using PowerShell. First, you need an account with sufficient privileges to connect. The Global Administrator will have access to the most management features and data across the services. However, Microsoft recommends you only have 2-4 Global Administrators in your tenant. In this case, you should assign the least permissive role needed for administrators to perform their job functions. Other roles include Global Reader, Groups Admin, and Helpdesk Admin.

There are two different modules that can manage Azure AD for Microsoft 365:

  • Azure Active Directory Module for Windows PowerShell