Skip to main content
This section covers PowerShell automation for the full Microsoft 365 and Azure ecosystem. Whether you need to manage mailboxes, provision SharePoint sites, configure Teams, administer Entra ID identities, or call the Microsoft Graph API, the scripts here handle the heavy lifting.

Required modules

Install the appropriate module before running scripts in each category.
ModuleServiceInstall command
ExchangeOnlineManagementExchange OnlineInstall-Module ExchangeOnlineManagement
Microsoft.Online.SharePoint.PowerShellSharePoint OnlineInstall-Module Microsoft.Online.SharePoint.PowerShell
MicrosoftTeamsTeamsInstall-Module MicrosoftTeams
Microsoft.GraphAzure AD / Entra IDInstall-Module Microsoft.Graph
AzureADAzure AD (legacy)Install-Module AzureAD
Microsoft.GraphMS Graph APIInstall-Module Microsoft.Graph
PowerShell 7+ is recommended for all Microsoft 365 modules. PowerShell 5.1 is supported but some modules may have limited functionality.

Connecting to each service

Each service requires its own connection command. Run these before executing any scripts.
# Exchange Online
Connect-ExchangeOnline -UserPrincipalName admin@yourdomain.com

# SharePoint Online
Connect-SPOService -Url https://yourdomain-admin.sharepoint.com

# PnP PowerShell (SharePoint)
Connect-PnPOnline -Url https://yourdomain.sharepoint.com -Interactive

# Microsoft Teams
Connect-MicrosoftTeams

# Azure AD / Entra ID (Microsoft.Graph)
Connect-MgGraph -Scopes "User.Read.All", "Group.ReadWrite.All"

# Azure AD (legacy module)
Connect-AzureAD

Script categories

Exchange & Exchange Online

Mailbox management, distribution groups, mail flow rules, and mailbox size reporting.

SharePoint & Teams

Site management, permissions, team provisioning, channel operations, and membership.

Azure AD & Entra ID

User management, group administration, and Conditional Access policy automation.

Microsoft Graph API

Cross-service automation using the Microsoft Graph PowerShell SDK.

Prerequisites

All scripts in this section require:
  • A Microsoft 365 tenant with appropriate licensing
  • An account with sufficient administrative permissions for the target service
  • PowerShell 5.1 or later (PowerShell 7+ recommended)
  • The relevant PowerShell module installed and imported
Always test scripts against a non-production environment or a small pilot group before running against your full tenant.

Build docs developers (and LLMs) love