Copy-ready Exchange PowerShell commands for connecting to Exchange Online or on-premises Exchange, checking mailbox and database health, and investigating mail flow.
PackageManagement\\Install-Package : Module ExchangeOnlineManagement was installed successfully.
Install the module once on the workstation. Use an account with permission to administer Exchange Online, and follow your organization's PowerShell execution and sign-in policies.
Connect-ExchangeOnline uses modern authentication and supports MFA. The -UserPrincipalName value selects the account; the interactive sign-in window handles the password and MFA challenge.
Connection established using app-only authentication.
Use app-only authentication for unattended automation. Register the application, grant the required Exchange application permissions, upload the certificate, and assign the appropriate Exchange role group before running this command.
Disconnect from Exchange Online
Disconnect-ExchangeOnline-Confirm:$false
Disconnect at the end of scripts and interactive sessions. This removes the remote session and imported Exchange Online cmdlets from the current PowerShell process.
DisplayName UserPrincipalName PrimarySmtpAddress RecipientTypeDetails
----------- ----------------- ------------------ --------------------
Jane Doe jane.doe@contoso.com jane.doe@contoso.com UserMailbox
Help Desk helpdesk@contoso.com helpdesk@contoso.com SharedMailbox
The Get-EXO* cmdlets are REST-backed and are generally preferred for Exchange Online administration. Use -ResultSize Unlimited deliberately because large result sets can take longer and consume more resources.
Received SenderAddress RecipientAddress Subject Status
-------- -------------- ----------------- ------- ------
10/20/2026 09:12 AM sender@external.net user@contoso.com Project update Delivered
Use Get-MessageTraceV2 for current Exchange Online message trace searches. Trace availability, date range, and retained data depend on the service and tenant licensing.
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential
Name Value
---- -----
ExchangeServer {Microsoft.Exchange.Commands...}
Replace FQDN with the Exchange server's fully qualified domain name. Run the commands from a domain-joined computer with network and Kerberos access to the server.
Close the session
Remove-PSSession$Session
Close the session when finished so imported Exchange cmdlets and the remote runspace do not remain open.
CommandType Name Version Source
----------- ---- ------- ------
Function Get-MailboxDatabase 15.2.1118 tmp_EXCH...
ComputerName State ConfigurationName
------------ ----- -----------------
ex01.contoso.com Open Microsoft.Exchange
DisplayName ItemCount TotalItemSize LastLogonTime
----------- --------- ------------- -------------
Jane Doe 18432 2.14 GB 10/20/2026 8:41 AM
Help Desk 9211 846.7 MB 10/20/2026 8:37 AM
TotalItemSize is an Exchange size object. For reporting or filtering, use Get-ExchangeDiagnosticInfo or convert the value deliberately rather than treating the displayed string as a number.
DisplayName Status PercentComplete BytesTransferred
----------- ------ --------------- ----------------
Jane Doe InProgress 62 1.31 GB
Confirm the target database and maintenance window before starting a move. Run Remove-MoveRequest -Identity jdoe only after understanding why the request is stuck or failed.
Add -Sender, -MessageSubject, or -MessageId to narrow a search. Message tracking retention and available fields vary by Exchange version and configuration.