M365 PowerShell Setup

Install PowerShell and the modules Microsoft 365 admin work needs, then connect to each service — top to bottom, no account needed. Optional update and uninstall/reinstall steps are there if something needs fixing.

Every module below needs current, cross-platform PowerShell (7+) — not the older 5.x powershell.exe that ships built into Windows.

Windows (winget)
winget install --id Microsoft.PowerShell --source winget
macOS (Homebrew)
brew install --cask powershell

Linux: installation varies by distribution (APT/YUM/Zypper/Snap packages, or a portable tarball) — see the Microsoft install docs link above for your specific distro.

Already installed? Check your version and upgrade if needed:

What version am I running
$PSVersionTable.PSVersion
Windows (winget)
winget upgrade Microsoft.PowerShell
macOS (Homebrew)
brew upgrade powershell

Check the modules you need — this drives the update, uninstall, and connect commands in Steps 3, 4, and 5.

Commands use -Force to skip the PSGallery untrusted-repository confirmation prompt.

Not sure what you already have? List every installed module and its version before installing anything:

Check installed modules & versions
Get-InstalledModule | Select-Object Name, Version
Install commands
Install
Install-Module ExchangeOnlineManagement -Scope CurrentUser -Force
Install
Install-Module Microsoft.Graph -Scope CurrentUser -Force
Install
Install-Module MicrosoftTeams -Scope CurrentUser -Force

Still current and supported for SharePoint Online tenant administration — but some newer capabilities are only available through Microsoft Graph PowerShell or PnP PowerShell.

Install
Install-Module Microsoft.Online.SharePoint.PowerShell -Scope CurrentUser -Force
Install
Install-Module Az -Scope CurrentUser -Force
Install
Install-Module PnP.PowerShell -Scope CurrentUser -Force

See what's currently installed, then update just the modules you're using.

Check installed modules & versions
Get-InstalledModule | Select-Object Name, Version
Update commands

Side-by-side installs: Update-Module installs the new version alongside the old one — old versions aren't removed automatically. Cleaning them up is optional housekeeping:

Remove old side-by-side versions (optional)
Get-InstalledModule | ForEach-Object { Get-InstalledModule -Name $_.Name -AllVersions | Sort-Object { [version]$_.Version } -Descending | Select-Object -Skip 1 | Uninstall-Module -Force }

Loaded-module gotcha: a module already loaded in the current session can't be cleanly updated. Close every PowerShell window and run the update from a fresh, elevated session.

A full uninstall and reinstall is the standard fix for a corrupted or version-conflicted module. Run these from an elevated PowerShell session with no other PowerShell windows open.

Commands use -Force to skip the confirmation prompt.

Uninstall commands

Each command above uses -AllVersions, so it also cleans up any side-by-side leftovers from Step 3's update gotcha.

To reinstall, use Step 2's Install-Module commands for the module(s) you checked there.

Fills in the connect commands below that need a tenant subdomain.

Connected? Browse the command reference M365 PowerShell Commands →