maxkabakov - Fotolia

Tip

Explore multiple Office 365 PowerShell management options

Why use PowerShell for Office 365 and Azure? In some instances, it's the only way to tap into some of the hidden management settings in these Microsoft cloud products.

With so many different services and capabilities available in its cloud products, Microsoft continues to develop and improve the ways to manage Office 365 and Azure.

The programming language of choice is typically PowerShell. The automation tool unlocks many powerful scripting opportunities for administrators who need to scale their management capabilities. The admin center in Microsoft 365/Office 365 can handle basic jobs, but PowerShell is oftentimes the only way to access settings that are hidden from the GUI management portal. PowerShell also opens the door to develop Office 365 automation scripts that make it easier and quicker to perform management tasks for hundreds or thousands of users.

With many different teams responsible for each feature of Office 365, a proliferation of different PowerShell modules has been introduced over time. There are consolidation efforts to simplify and make management with this automation tool easier, but there remain multiple methods available for Office 365 PowerShell management.

Manage Office 365 via Azure modules

Beneath Office 365 is Microsoft Azure's infrastructure and platform. The Azure AD module contains much of the functionality needed to manage the Azure Active Directory side of Office 365. This module is based on the public Graph API exposed by Microsoft to help IT work with Azure resources. Some of the features contained in this module include management of applications, devices, groups, roles and users.

Installing the Azure AD module is simple and can be done by using PowerShellGet to install from the PowerShell Gallery. Although you can use this module in PowerShell 7 (or Core) on Windows using the -UseWindowsModule switch of Import-Module, there is functionality that may not work as expected due to the serialization of the command output.

Install-Module -Name 'AzureAD'

What about the MSOnline module?

Before the Azure AD module, Microsoft offered the MSOnline module for PowerShell users.  This release was the first module intended to manage all aspects of Azure. Built on a nonpublic API, MSOnline has functionality that has not yet been ported to the Azure AD module.

An example of this older module's capability that doesn't currently exist in the Azure AD module is directory sync used to synchronize on-premises domains objects to Azure Active Directory.

Although Microsoft is not adding new features to the MSOnline module, you can install it side by side with the Azure AD module. Much like the Azure AD module, it's important to note that, although you can use this module in PowerShell 7 (or Core) on Windows using the -UseWindowsModule switch of the Import-Module command, there is functionality that may not work as expected due to the serialization of command output.

Install-Module -Name 'MSOnline'

Using the newer Azure PowerShell modules

Where does the new Azure PowerShell module -- sometimes referred to as the Az PowerShell module in Microsoft's documentation -- fit into the PowerShell management landscape? The module replaces the AzureRM module, which was produced to manage all aspects of Azure.

Although still a work in progress, the Az PowerShell module continues to pick up commands from Microsoft developers. The commands themselves are too numerous to list for this article, but they encompass many different aspects of Azure from containers to cost management.

The Az module is cross-platform compatible and works in the latest PowerShell versions. The recommended method of installation is under the CurrentUser. To install from the PowerShell Gallery, use the following command:

Install-Module -Name 'Az' -AllowClobber -Scope 'CurrentUser'

More than one way to manage SharePoint with PowerShell

Many aspects of PowerShell are built on an underlying framework of SharePoint. There are two main modules for managing SharePoint in the Azure environment. For most typical administrative tasks and individual site management, you can use the SharePoint Online Management Shell, which is installed via the PowerShell Gallery:

Install-Module -Name 'Microsoft.Online.SharePoint.PowerShell'

There is a secondary module named SharePoint Patterns and Practices (PnP) for complicated provisioning and artifact administrative tasks with SharePoint. Similar to the Online Management Shell, you can install SharePoint PnP via the PowerShell Gallery:

Install-Module -Name 'SharePointPnPPowerShellOnline'

Microsoft Teams PowerShell management

Managing Microsoft Teams has gotten much easier with the availability of the Microsoft Teams module, which consists primarily of wrapping Graph API calls into an easier-to-use command framework. With this module, you can quickly create and manage new and existing Teams.

Install-Module -Name 'MicrosoftTeams'

There are known issues with PowerShell 7 and the Microsoft Teams module. The recommended client is Windows PowerShell 5.1. For open source PowerShell versions, you may be able to use the -UseWindowsPowerShell switch in the Import-Module, but your mileage may vary in terms of functionality.

How to manage Exchange Online via PowerShell

Finally, another core responsibility of Office 365 to deliver email using the Exchange Online infrastructure. Being able to easily manage this environment is critical to many business operations. Currently, the recommended module to use is the Exchange Online Management v2 module, also known as EXOv2. Install this module in an elevated PowerShell prompt using the following command:

Install-Module -Name 'ExchangeOnlineManagement'

When you first import this module, you will find only a handful of unique commands. Microsoft optimized these for bulk data retrieval and more efficiency than traditional Exchange Online Management commands.

To manage all aspects of Exchange Online, you simply need to connect to Exchange, and the other commands will become available along with the new EXOv2 commands.

Connect-ExchangeOnline -UserPrincipalName '[email protected]' -ShowProgress $true

Managing the expansive Office 365 ecosystem requires many tools

As you can see, there are many ways to connect to Office 365 and Azure. This article does not cover every possible option, as there are quite a few independently developed modules with extensive capabilities. Quick and effective Azure and Office 365 PowerShell management helps administrators be more efficient in addressing the rapidly changing needs of the enterprise.

Dig Deeper on