PowerShell Exchange Online Commands
This guide provides essential commands for managing Exchange Online using the ExchangeOnlineManagement module.
Parent Topic: PowerShell Comprehensive Guide
1. Connecting to Exchange Online
First, ensure the module is installed:
Install-Module -Name ExchangeOnlineManagement -Scope CurrentUser
Then, connect to your tenant. This will prompt for modern authentication (MFA).
Connect-ExchangeOnline -UserPrincipalName "admin@yourdomain.com"
To disconnect when you are finished:
Disconnect-ExchangeOnline
2. Mailbox Management
Find Mailboxes
# Get a specific mailbox
Get-Mailbox -Identity "user@yourdomain.com"
# Get all user mailboxes
Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox
# Get all shared mailboxes
Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails SharedMailbox
Mailbox Permissions
# Grant Full Access permission
Add-MailboxPermission -Identity "shared.mailbox@yourdomain.com" -User "user@yourdomain.com" -AccessRights FullAccess -InheritanceType All
# Grant Send As permission
Add-RecipientPermission -Identity "shared.mailbox@yourdomain.com" -Trustee "user@yourdomain.com" -AccessRights SendAs
Mailbox Forwarding
# Set up email forwarding and keep a copy in the original mailbox
Set-Mailbox -Identity "user.a@yourdomain.com" -DeliverToMailboxAndForward $true -ForwardingSmtpAddress "user.b@yourdomain.com"
# Remove forwarding
Set-Mailbox -Identity "user.a@yourdomain.com" -ForwardingSmtpAddress $null
3. Mail Flow & Transport Rules
# Get all transport rules
Get-TransportRule
# Create a rule to prepend a subject for external emails
New-TransportRule -Name "External Mail Warning" -FromScope NotInOrganization -ApplyHtmlDisclaimerLocation Prepend -ApplyHtmlDisclaimerText "<p><div style='background-color:#FFEB9C; padding:5px; border:1px solid <a href='/?search=%237D6608' class='obsidian-tag'>#7D6608</a>;'><strong>CAUTION:</strong> This email originated from outside of the organization.</div></p>"
Return to PowerShell Comprehensive Guide