This article covers how to connect to powershell using a regular M365 global admin user and computer. Another “internal only” article is available regarding the usage of powershell using a M365 partner delegated access. Link


TABLE OF CONTENTS

 

Requirements

Must use a 64bit Windows 7 OS or more recent. Must be global admin of the M365 tenant or have an admin role for the specific service to connect to. The powershell modules must be installed (instruction bellow) prior to be able to use their corresponding cmdlets.

 

Install the powershell modules:


1. Run powershell as administrator.

Graphical user interface, application

Description automatically generated

* If you are not admin on your machine. You can add “-Scope CurrentUser” to your command when installing modules.


2. Type: Set-executionPolicy remotesigned

*Only necessary if there is a need to run scripts.


3. Type: Install-module -name “module name

Example: Install-module -name msonline          (A list of M365 modules is available lower in this article)

*If you get a message about NuGet version 2.** or newer, you can safely accept.

*If you add “-force” to your cmd. It will override possible version conflicts and install the latest version available.

Text

Description automatically generated with medium confidence

 

M365 modules available and how to connect to them

With some modules you can connect with: Connect-module nameBut the name to use or command may vary from the name used to install them. All the listed modules use modern authentication so you will get a normal Microsoft sign-in prompt that supports multi-factor authentication.

 

MSOnline

(manage users, licenses, domains, tenant settings...) Article link:  MSOnline

To install the module:

Install-module -name MSOnline

To connect:

Connect-MsolService

 

Exchange

(manage mailboxes, mail flow settings, spam policy...) Article link:  EOM

To install the module:

Install-module -name ExchangeOnlineManagement

To connect:

Connect-ExchangeOnline

 

Security & Compliance

(manage some EOP and DLP features and policies) Article link: IPP

The cmdlets are installed with the ExchangeOnlineManagement module.

To connect:

Connect-IPPSSession

 

AzureAD

(manage users, groups, contacts, devices, active directory...) Article link: AzureAD

*will eventually get deprecated and replaced by Microsoft.Graph.

To install the module:

Install-module -name AzureAD

To connect:

Connect-AzureAD

 

Teams

(manage Teams, channels, phone systems,…) Article link: MicrosoftTeams

*Some Skype For Business cmdlets are still used for some Teams features but they are included in this module.

To install the module:

Install-module -name MicrosoftTeams

To connect:

Connect-MicrosoftTeams

 

Microsoft Graph

(interact with all M365 services, will eventually replace many modules) Article link: Microsoft.Graph

To install the module:

Install-Module -Name Microsoft.Graph

To connect:

Connect-MgGraph

 

Azure Information Protection

(manage Azure Information Protection, Rights Management…) Article link: AIPService

*This module replaces AADRM. You must uninstall AADRM before installing it, if it is already installed on your machine.

To install the module:

Install-module -name AIPService

To connect:

Connect-AIPService

 

SharePoint

(manage SharePoint sites and features, manage OneDrive) Article link: MOSP

To install the module:

Install-module -name Microsoft.Online.SharePoint.PowerShell

To connect:

Connect-SPOService -Url https://”tenant name”-admin.sharepoint.com

The “tenant name” here correspond to the first part of the onmicrosoft.com domain. Example for contoso.onmicrosoft.com

Connect-SPOService -Url https://contoso-admin.sharepoint.com

 

PnP.PowerShell

(open-source cmdlets that interact with all M365 services) Article link: PnP

To install the module:

Install-module -name PnP.PowerShell

The connection method varies depending on the service you connect to. Article link: Guide

 

 

 

General Powershell management features:

 

Verify which modules are installed on the computer:

Get-InstalledModule

 

Uninstall a module:

Uninstall-Module -Name “module name

 

See which cmdlets are available with a specific module:

Get-Command -module “module name

 

Update the modules:

Update-Module -Name “module name

All at once: 

Update-Module

 

Install a specific version of a module:

Install-Module -Name “module name” -RequiredVersion 2.0.0

 

Install a module only for the current user or without admin rights:

Install-Module -Name “module name” -Scope CurrentUser

 

Record the powershell session. (transcript):

Specify the path and txt file name in the following cmd where a txt file will be exported containing a recording of the powershell session. Example:

Start-Transcript -Path "C:\transcripts\name.txt" -NoClobber

Do your actions and cmds that you want to record and then stop the transcript with:

Stop-Transcript

A txt file will be created at the specified path.

 

Show truncated results

Run this command before doing your action that created truncated results:

$FormatEnumerationLimit =-1


Export the result of a cmd to a .csv file

You can add “| export-csv “path” to your cmd and replace “path” with the path on your computer where the file will be created. Example:

get-Mailbox | Select-Object DisplayName,PrimarySmtpAddress | export-csv C:\export\mailbox_list.csv