Exchange Online PowerShell Command Builder

Generate correct Exchange Online PowerShell commands for mailbox permissions, forwarding audits, message trace, groups, calendars and reports.

Advertisement

Free Exchange Online PowerShell Command Builder

This tool builds ready-to-run Exchange Online PowerShell commands from a form. Pick a task — grant Full Access to a shared mailbox, audit tenant-wide mail forwarding, run a message trace, create a distribution group, report on mailbox sizes — fill in the mailbox address or username, and the correct cmdlet syntax is generated with the connection preamble already attached. Around forty tasks are covered across nine categories. Everything is generated in your browser; nothing you type is sent anywhere, and the tool never connects to your tenant.

It is aimed at the Microsoft 365 administrator who knows exactly what needs to happen but not the exact parameter names — which is most of us, most of the time. Is it -User or -Trustee? Does Send As use Add-MailboxPermission or Add-RecipientPermission? Is Get-MessageTrace still a thing? The builder answers those questions by producing correct syntax rather than by making you look each one up.

Prerequisites: Install the Module and Connect

Every task except the install itself assumes you are connected. Install the module once:

Install-Module -Name ExchangeOnlineManagement -Scope CurrentUser -Force

Later, update it with:

Update-Module -Name ExchangeOnlineManagement

Then connect. Interactive sign-in handles MFA through a browser prompt:

Connect-ExchangeOnline -UserPrincipalName admin@contoso.com -ShowBanner:$false

And always disconnect when you are done, so you do not leave a session holding a token:

Disconnect-ExchangeOnline -Confirm:$false

The builder also covers certificate-based authentication (Connect-ExchangeOnline -CertificateThumbprint with an app ID and organisation, for unattended scripts), app-only authentication with a managed identity (Connect-ExchangeOnline -ManagedIdentity), and the -DisableWAM switch that resolves the Web Account Manager broker sign-in failures some workstations hit. For a full walkthrough of installing the module, dealing with execution policy and troubleshooting first-connection errors, see our guide on how to install and connect to Exchange Online PowerShell.

The Nine Task Categories

  • Connect & Setup — install the module, connect interactively or with MFA, certificate-based and managed-identity authentication, WAM troubleshooting, disconnect.
  • Mailbox Permissions — grant and remove Full Access, Send As and Send on Behalf; list who currently has access to a mailbox.
  • Mail Forwarding — set forwarding to an internal or external address, remove it, and audit forwarding across the entire tenant.
  • Shared Mailboxes — create a shared mailbox, convert a user mailbox to shared, add members and control auto-mapping.
  • Groups — create distribution groups, add and remove members, bulk-add from a CSV, list membership, allow external senders.
  • Message Trace — trace by sender, by recipient, or by delivery status over a chosen number of days.
  • Calendar Permissions — view, grant and change calendar access at every permission level from AvailabilityOnly to PublishingEditor.
  • Transport Rules — list rules, disable a rule, and create a rule blocking external auto-forwarding.
  • Reporting — mailbox size reports, last logon reports, mailboxes near quota, inactive mailboxes and recipient-type breakdowns, exported to CSV.

Each task also shows the underlying cmdlet and the role or permission you need to run it — Exchange Administrator for most changes, View-Only Recipients or Global Reader for the read-only reports.

Worked Example: The Three Kinds of Mailbox Permission

This is the area where the wrong cmdlet gets used most often, because the three permissions look similar and behave completely differently.

Full Access lets someone open the mailbox and read everything in it. It does not let them send as the mailbox:

Add-MailboxPermission -Identity "shared@contoso.com" `
    -User "jdoe@contoso.com" `
    -AccessRights FullAccess -InheritanceType All -AutoMapping $true

Send As makes mail appear to come from the mailbox itself, with no trace of the actual sender in the From line. It is a different cmdlet entirely — Add-RecipientPermission, with -Trustee rather than -User:

Add-RecipientPermission -Identity "shared@contoso.com" `
    -Trustee "jdoe@contoso.com" `
    -AccessRights SendAs -Confirm:$false

Send on Behalf shows recipients “jdoe on behalf of shared”, and is set as a property of the mailbox:

Set-Mailbox -Identity "shared@contoso.com" `
    -GrantSendOnBehalfTo @{Add="jdoe@contoso.com"}

Two practical notes. The @{Add=…} hashtable syntax on -GrantSendOnBehalfTo appends to the existing list; assigning a plain value replaces it, silently removing everyone else. And -AutoMapping $true makes the shared mailbox appear automatically in Outlook, which is usually what people want — but for a mailbox with tens of thousands of items it can slow Outlook noticeably, so set it to $false and have users add the mailbox manually in that case.

Worked Example: Auditing Mail Forwarding

Attacker-configured mail forwarding is one of the most durable post-compromise persistence techniques in Microsoft 365, and it hides in two separate places. Server-side forwarding is a mailbox property; user-created inbox rules are separate objects. A complete audit checks both:

# Every mailbox with server-side forwarding configured
Get-EXOMailbox -ResultSize Unlimited -PropertySets Delivery |
    Where-Object { $_.ForwardingAddress -or $_.ForwardingSmtpAddress } |
    Select-Object DisplayName, PrimarySmtpAddress, ForwardingAddress,
        ForwardingSmtpAddress, DeliverToMailboxAndForward |
    Export-Csv -Path "C:\Reports\forwarding.csv" -NoTypeInformation

User-created inbox rules that forward or redirect

Get-EXOMailbox -ResultSize Unlimited | ForEach-Object { Get-InboxRule -Mailbox $.PrimarySmtpAddress | Where-Object { $.ForwardTo -or $.ForwardAsAttachmentTo -or $.RedirectTo } }

Run the audit, then close the gap with a transport rule that blocks external auto-forwarding outright — the builder generates that rule too. Note the Get-EXO* cmdlets used here: the REST-backed V3 cmdlets such as Get-EXOMailbox are substantially faster than their classic equivalents on large tenants, and -PropertySets keeps the payload small by fetching only the property group you need.

Worked Example: Message Trace

When a user reports a missing message, trace it:

Get-MessageTraceV2 -SenderAddress "sender@contoso.com" `
    -StartDate (Get-Date).AddDays(-7) -EndDate (Get-Date) |
    Format-Table Received, SenderAddress, RecipientAddress, Subject, Status -AutoSize

Get-MessageTraceV2 covers up to 90 days and replaces the retired Get-MessageTrace. If you have older scripts still calling the original cmdlet, that is why they stopped working. You can also filter by delivery status — Failed, Delivered, Pending, Quarantined or FilteredAsSpam — which is usually the fastest route to a deliverability answer.

Before You Run Anything

These commands change production mail flow and access. Read the generated command before running it, run reporting tasks before change tasks, and test permission and forwarding changes on a single test mailbox first. Bulk operations built from a CSV in particular deserve a dry run — pipe to Select-Object and inspect the list before you pipe it to a cmdlet that writes.

Related Tools

Mail-flow problems that turn out to be DNS problems are common: check the domain’s records with the DNS lookup tool, and build or repair authentication records with the SPF generator and DMARC generator. For CSV and report output you need to reshape, the JSON formatter is a useful companion.

Frequently Asked Questions

How do I install the Exchange Online PowerShell module?

Run Install-Module -Name ExchangeOnlineManagement -Scope CurrentUser -Force. Drop -Scope CurrentUser and run PowerShell as administrator if you want it installed for all users on the machine.

How do I connect to Exchange Online PowerShell with MFA?

Use Connect-ExchangeOnline -UserPrincipalName admin@contoso.com. The V3 module handles multi-factor authentication through an interactive browser prompt by default — there is no separate MFA module any more.

Does this tool connect to my tenant?

No. It generates command text only. Nothing you enter — mailbox addresses, tenant names, app IDs, thumbprints — leaves your browser, and no credentials are ever requested.

What is the difference between Full Access and Send As?

Full Access lets someone open and read a mailbox. Send As lets them send mail that appears to originate from it. They are separate permissions set by different cmdlets, and delegating a shared mailbox usually requires both.

Why can my delegate open the mailbox but not send from it?

Because Full Access was granted and Send As was not. Add the Send As permission with Add-RecipientPermission. Also allow time for the change to replicate — permission changes in Exchange Online are not always instant.

What replaced Get-MessageTrace?

Get-MessageTraceV2. It supports a 90-day window and is the supported cmdlet going forward; the original has been retired.

What are the Get-EXO cmdlets?

REST-backed V3 cmdlets such as Get-EXOMailbox and Get-EXOMailboxStatistics, designed for bulk and reporting work. They are considerably faster on large tenants and support -PropertySets to limit which properties are retrieved.

How do I run Exchange Online PowerShell unattended?

Use certificate-based app-only authentication: register an Entra ID application, grant it the Exchange.ManageAsApp permission, upload a certificate, and connect with Connect-ExchangeOnline -CertificateThumbprint <thumbprint> -AppId <app-id> -Organization contoso.onmicrosoft.com. On an Azure-hosted runner, a managed identity avoids handling a certificate at all.

What roles do I need?

Exchange Administrator covers most changes. Read-only reporting and message trace generally need only View-Only Recipients or Global Reader. Each task in the builder states its own requirement, so you can request the minimum rather than defaulting to Global Administrator.

Why does my connection fail with a broker or WAM error?

Some workstations hit failures in the Web Account Manager sign-in broker. Add -DisableWAM to Connect-ExchangeOnline to fall back to the browser-based flow. The builder includes this as a dedicated task.

What Is Exchange Online PowerShell

Exchange Online PowerShell provides administrative command-line access to Microsoft Exchange Online, the cloud-based email and calendaring service in Microsoft 365. While the Exchange Admin Center (EAC) provides a web-based GUI, PowerShell enables bulk operations, automation, and access to advanced settings not available in the portal.

Exchange Online PowerShell is essential for managing mailboxes, distribution groups, mail flow rules, retention policies, and compliance features at enterprise scale. Operations that would require hours of clicking in the admin portal can be completed in seconds with the right PowerShell commands.

Common Command Categories

CategoryExample CommandsPurpose
Mailbox ManagementGet-Mailbox, Set-Mailbox, New-MailboxCreate, configure, and query mailboxes
Distribution GroupsGet-DistributionGroup, Add-DistributionGroupMemberManage email groups and membership
Mail Flow RulesGet-TransportRule, New-TransportRuleConfigure mail routing and filtering rules
PermissionsAdd-MailboxPermission, Get-MailboxFolderPermissionManage mailbox delegation and folder access
ComplianceGet-RetentionPolicy, New-ComplianceSearchConfigure retention, eDiscovery, and audit policies
Anti-SpamGet-HostedContentFilterPolicyManage spam filtering and quarantine settings
Mobile DevicesGet-MobileDeviceStatisticsManage ActiveSync and mobile device policies

Common Use Cases

  • Bulk mailbox operations: Set out-of-office messages, change mailbox quotas, or update properties for hundreds of mailboxes using CSV imports
  • Shared mailbox management: Create shared mailboxes, assign full access and send-as permissions, and configure auto-mapping for delegate access
  • Mail flow troubleshooting: Trace message delivery paths, review transport rules, and diagnose delivery failures
  • Compliance configuration: Set up retention policies, litigation holds, and eDiscovery searches for legal and regulatory requirements
  • Migration assistance: Export mailbox statistics, identify large mailboxes, and prepare user lists for migrations between Exchange environments

Best Practices

  1. Use the EXO V3 module — Connect using Connect-ExchangeOnline from the ExchangeOnlineManagement module (v3+). This supports modern authentication, certificate-based auth, and REST-based cmdlets.
  2. Limit result sets — Use -ResultSize to limit query results. Querying all mailboxes in a large tenant without limits can timeout or consume excessive resources.
  3. Use -WhatIf for destructive operations — Before running Set- or Remove- commands on multiple objects, add -WhatIf to preview what would change without making actual modifications.
  4. Implement error handling in scripts — Wrap bulk operations in try/catch blocks and log failures. A single failed mailbox operation should not halt processing of the remaining batch.
  5. Disconnect sessions when finished — Always run Disconnect-ExchangeOnline when done. Exchange Online limits the number of concurrent PowerShell sessions per tenant.

Frequently Asked Questions

How do I connect to Exchange Online with PowerShell?+

First install the module with Install-Module -Name ExchangeOnlineManagement -Scope CurrentUser -Force. Then run Connect-ExchangeOnline -UserPrincipalName admin@contoso.com. A browser prompt handles sign-in and MFA automatically. For unattended scripts use certificate-based auth (Connect-ExchangeOnline -AppId ... -CertificateThumbprint ... -Organization ...) or app-only auth with a managed identity. Always finish with Disconnect-ExchangeOnline.

How do I grant someone access to another mailbox?+

There are three distinct permissions. Use Add-MailboxPermission -Identity target@contoso.com -User jdoe@contoso.com -AccessRights FullAccess for full access (opening the mailbox). Use Add-RecipientPermission ... -AccessRights SendAs for Send As (mail appears to come from the mailbox). Use Set-Mailbox -GrantSendOnBehalfTo for Send on Behalf. The builder generates the exact command for each.

How do I set or remove email forwarding on a mailbox?+

For an internal recipient use Set-Mailbox -ForwardingAddress; for an external SMTP address use -ForwardingSmtpAddress. Add -DeliverToMailboxAndForward $true to keep a copy in the original mailbox. To stop forwarding, set both -ForwardingAddress $null and -ForwardingSmtpAddress $null. Note that external auto-forwarding is often blocked by the outbound anti-spam policy.

How do I audit all email forwarding across the tenant?+

This is a key security check. Run Get-EXOMailbox -ResultSize Unlimited and filter where ForwardingAddress or ForwardingSmtpAddress is set, then export to CSV. Also enumerate user-created inbox rules with Get-InboxRule and flag any with ForwardTo, ForwardAsAttachmentTo, or RedirectTo, since attackers commonly use these to exfiltrate mail. The Forwarding category in this tool builds the full audit script.

How do I create a shared mailbox or convert an existing one?+

Create one with New-Mailbox -Shared -Name "Support" -PrimarySmtpAddress support@contoso.com, then grant members FullAccess and SendAs. To convert an existing user mailbox, run Set-Mailbox -Identity user@contoso.com -Type Shared. Shared mailboxes under 50 GB do not require a license, so remember to remove the license after converting.

Why does Get-MessageTrace no longer work, and what replaces it?+

Microsoft retired the original Get-MessageTrace and Get-MessageTraceDetail cmdlets. Use Get-MessageTraceV2 instead. It supports searching by sender, recipient, date range (up to 90 days), and delivery status (Failed, Delivered, Pending, Quarantined, FilteredAsSpam). The Message Trace category in this tool generates V2 commands.

How do I manage calendar sharing permissions in PowerShell?+

View current permissions with Get-MailboxFolderPermission -Identity user@contoso.com:\Calendar. Grant new access with Add-MailboxFolderPermission and an access level such as Reviewer, Editor, or AvailabilityOnly. If the user is already listed you must use Set-MailboxFolderPermission instead of Add-, otherwise the command errors. The builder picks the correct cmdlet for you.

What if Connect-ExchangeOnline hangs or throws a WAM error?+

On servers or non-interactive desktops the Web Account Manager (WAM) broker can cause the sign-in window to hang or fail. Add the -DisableWAM switch: Connect-ExchangeOnline -UserPrincipalName admin@contoso.com -DisableWAM. This falls back to the standard browser-based auth flow. Keeping the module updated with Update-Module ExchangeOnlineManagement also resolves many auth issues.

This tool is provided for informational and educational purposes only. All processing happens in your browser — no data is sent to or stored on our servers. While we strive for accuracy, we make no warranties about the completeness or reliability of results.