A collection of useful PowerShell commands for managing Exchange Online in a hybrid setup. These commands help with mailbox management, delegation, forwarding, archiving, migrations, and more.
This repository provides a set of practical PowerShell commands for managing Microsoft Exchange Online in a hybrid environment. It's designed for sysadmins and IT professionals who regularly work with mailbox reporting, delegation, and compliance-related tasks.
All commands are tested in hybrid configurations with directory sync (AAD Connect) enabled.
Before using these commands, ensure:
- You have the Exchange Online PowerShell V2 (EXO V2) module installed
- You are connected to Exchange Online PowerShell
- You have sufficient permissions (e.g. View-Only Recipients, Recipient Management, etc.)
Connect-ExchangeOnline -UserPrincipalName youradmin@yourdomain.com
Get-Mailbox -ResultSize Unlimited | Select DisplayName,PrimarySMTPAddress
Get-Mailbox -InactiveMailboxOnly -ResultSize Unlimited | Select DisplayName, PrimarySMTPAddress, DistinguishedName, ExchangeGuid, WhenSoftDeleted, @{Name="Aliases";Expression={$_.EmailAddresses -match "^smtp:" -replace "smtp:" -join "; "}} | Export-Csv -Path "C:\Temp\InactiveMailboxes.csv" -NoTypeInformation -Encoding UTF8
Get-Mailbox -RecipientTypeDetails SharedMailbox -ResultSize Unlimited | Select DisplayName,PrimarySMTPAddress
Get-Mailbox -ResultSize Unlimited | Select DisplayName,PrimarySMTPAddress, @{Name="FullAccess";Expression={(Get-MailboxPermission $_.Identity | Where-Object {($_.AccessRights -match "FullAccess") -and ($_.User -notmatch "NT AUTHORITY\\SELF")} | Select-Object User -ExpandProperty User) -join ", "}}, @{Name="SendAs";Expression={(Get-RecipientPermission $_.Identity | Where-Object {($_.AccessRights -match "SendAs")} | Select-Object Trustee -ExpandProperty Trustee) -join ", "}}
Get-Mailbox -ResultSize Unlimited | Where-Object { $_.ForwardingSMTPAddress -or $_.ForwardingAddress } | Select DisplayName,PrimarySMTPAddress,ForwardingSMTPAddress,ForwardingAddress,DeliverToMailboxAndForward
Get-Mailbox -Archive -ResultSize Unlimited | Select DisplayName,PrimarySMTPAddress,ArchiveStatus
Get-Mailbox -Archive -ResultSize Unlimited | Select DisplayName,PrimarySMTPAddress,ArchiveStatus
Get-MailboxStatistics -Identity user@domain.com | Select DisplayName,LastLogonTime
Get-TransportRule | Select Name,Mode,Priority,Comments
Get-MailboxStatistics -Identity user@domain.com | Select DisplayName,TotalItemSize,ItemCount
Get-Mailbox -ResultSize Unlimited | Where-Object { $_.ForwardingSMTPAddress -match "@" -and $_.ForwardingSMTPAddress -notmatch "yourdomain.com" } | Select DisplayName,PrimarySMTPAddress,ForwardingSMTPAddress
Get-Mailbox -ResultSize Unlimited | Select DisplayName, GrantSendOnBehalfTo
Get-Mailbox -ResultSize Unlimited | Where-Object { $_.LitigationHoldEnabled -eq $true } | Select DisplayName, LitigationHoldDate
Get-Mailbox -ResultSize Unlimited | Where-Object { $_.LitigationHoldEnabled -or $_.InPlaceHolds.Count -gt 0 } | Select DisplayName,LitigationHoldEnabled,InPlaceHolds
Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Where-Object { $_.TotalItemSize.Value.ToMB() -gt 5000 } | Select DisplayName,TotalItemSize
Get-Mailbox -ResultSize Unlimited | Where-Object { $_.RecipientTypeDetails -eq "UserMailbox" -and $_.AuditEnabled -eq $false } | Select DisplayName,PrimarySMTPAddress
Get-TransportRule
Get-TransportRule | Where-Object { $_.SentToScope -eq "NotInOrganization" -or $_.FromScope -eq "NotInOrganization" } | Select Name,Comments
Get-Mailbox -ResultSize Unlimited | Select DisplayName,ProhibitSendQuota,ProhibitSendReceiveQuota,IssueWarningQuota
Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Where-Object {
$_.StorageLimitStatus -eq "IssueWarning" -or $_.StorageLimitStatus -eq "ProhibitSend"
} | Select DisplayName,TotalItemSize,StorageLimitStatus
Get-InboxRule -Mailbox user@domain.com | Where-Object { $_.ForwardTo -ne $null -or $_.RedirectTo -ne $null } | Select Name,ForwardTo,RedirectTo
Pull requests are welcome. If you have a useful snippet to share or corrections to suggest, feel free to contribute!