PowerShell for Microsoft 365

Many admin tasks in Microsoft 365 go faster with PowerShell: changing a hundred users, building a report or changing a setting that isn't in the admin center. This guide covers which modules you need, how to connect and where to read on.

1. Get ready

2. The main modules

ModuleUsed forInstall
Microsoft GraphUsers, groups, licenses, Entra IDInstall-Module Microsoft.Graph
Exchange OnlineMailboxes, permissions, mail flowInstall-Module ExchangeOnlineManagement
Microsoft TeamsTeams, channels, policiesInstall-Module MicrosoftTeams
SharePoint OnlineSites, storage, sharingInstall-Module Microsoft.Online.SharePoint.PowerShell

More detail: the Exchange Online module and the Teams module.

3. Connect

Connect-MgGraph -Scopes "User.Read.All","Group.Read.All"
Connect-ExchangeOnline -UserPrincipalName admin@yourdomain.com
Connect-MicrosoftTeams

You sign in in a browser window, with MFA. See connect to Exchange Online PowerShell with MFA.

4. First commands

Get-MgUser -All | Select DisplayName, UserPrincipalName
Get-Mailbox -ResultSize Unlimited | Select DisplayName, RecipientTypeDetails
Get-Team | Select DisplayName, Visibility

Always start with Get- commands to look before you change anything with Set- or Remove-. Add -WhatIf to see what a command would do.

5. Read on

Read also

Install, update and use PowerShell 7 on Windows
Install the Exchange Online PowerShell module (ExchangeOnlineManagement)
Install and use the Microsoft Teams PowerShell module

Nederlandstalige versie: PowerShell voor Microsoft 365: een handleiding voor beginners


More in English