Skip to the main content.

ScriptRunner Blog

Managing Microsoft Exchange with PowerShell

Table of contents



Post Featured Image

Automating recurring Microsoft Exchange and Exchange Online tasks with PowerShell is key for successful IT professionals and system engineers. This article explores six PowerShell use cases for managing Microsoft Exchange.

Microsoft Exchange and Exchange Online remains a cornerstone for email, calendar, and contacts within many organizations. As Exchange environments grow in complexity, administrators seek tools that can streamline management tasks. PowerShell, with its powerful command-line shell and scripting language, offers a robust solution for managing Exchange (Online) more efficiently than traditional graphical user interfaces (GUIs). 


Why use PowerShell for Microsoft Exchange management?

  • Automation: PowerShell scripts automate repetitive tasks, ensuring consistency and saving time.
  • Access to a wide range of features: Some Exchange settings and features are only accessible through PowerShell, offering more control over the system.
  • Batch operations: PowerShell allows for batch processing of tasks, such as updating multiple mailboxes simultaneously, which is cumbersome through GUIs.
  • Remote management: Administrators can manage Exchange environments remotely via PowerShell, a necessity for managing servers across multiple locations.
  • Integration: PowerShell scripts can integrate with other systems and services, providing a unified approach to IT administration.

Let's take a look at some real-life use cases for Microsoft Exchange PowerShell automation.


Cmdlet 1: Get-Mailbox

Get-Mailbox retrieves information about mailboxes in your Exchange (Online) environment.

This one-liner quickly audits mailbox settings and status across the entire organization:

Get-Mailbox -ResultSize Unlimited | Format-Table DisplayName, ServerName, ProhibitSendQuota 


Cmdlet 2: Get-EXOMailbox

The Get-EXOMailbox is only available in Exchange Online.  It provides details of Exchange Online mailbox properties and settings. The following example combines Get-EXOMailbox with the Get-EXOMailboxStatistics cmdlet and shows the 10 largest mailboxes in the environment.

Get-EXOMailbox -ResultSize Unlimited | Get-EXOMailboxStatistics | Sort-Object TotalItemSize -Descending | Select-Object DisplayName,TotalItemSize -First 10


Cmdlet 3: Set-Mailbox

The Set-Mailbox cmdlet allows you to configure mailbox properties. You can change more than 130 mailbox settings, for example quotas or permissions. The following code examples contain the -WhatIf parameter. It allows simulating and test the results first. 

 Get-User | where {$_.Department -eq "Sales"} | Get-Mailbox | Set-Mailbox -ProhibitSendQuota 5GB -ProhibitSendReceiveQuota 5GB -IssueWarningQuota 4GB -Whatif 


Cmdlet 4: Get-DistributionGroup

You want to find existing distribution groups? Then Get-DistributionGroup is the right cmdlet. The following example shows all attributes of distribution groups that contain the name "Consulting".  

Get-DistributionGroup -Filter {name -like "*Consulting*"} |Select-Object * |Out-GridView



Cmdlet 5: New-Mailbox

With New-Mailbox you can create one or multiple Exchange mailboxes. Here's an example to create new maiboxes basedn on a csv file.  

$mbxs = Import-Csv 'C:\users.csv'
Foreach ($mbx in $mbxs) {
New-Mailbox -Name $mbx.DisplayName -DisplayName $mbx.DisplayName -MicrosoftOnlineServicesID $mbx.UserPrincipalName -Password (ConvertTo-SecureString -String 'YourPassword' -AsPlainText -Force) -ResetPasswordOnNextLogon $true -MailboxPlan 'MailboxPlan'


Cmdlet 6: Set-MailboxAutoReplyConfiguration

Use the Set-MailboxAutoReplyConfiguration cmdlet to activate out-of-office notifications for your users. It allows you to enable messages for an unlimited time or to schedule them for a specific period of time. 

$autoReplyParams = @{
Identity = ""
AutoReplyState = "Enabled"
ExternalMessage = "Hello, I'm currently not in the office."
InternalMessage = "Hello colleague, I'm currrently not in the office"
Set-MailboxAutoReplyConfiguration @autoReplyParams



Utilizing PowerShell for managing Exchange, whether On-Premises or Online, provides a high level of efficiency, flexibility, and control. The cmdlets listed above are fundamental tools for administrators to perform a wide range of tasks more effectively than through GUIs. By mastering these cmdlets, administrators can ensure their Exchange environments are well-managed, secure, and tailored to their organization's needs. Learn more about managing Exchange (Online) with PowerShell in our webinar "Simplify your Exchange (Online) administration with PowerShell".




Simplify your Exchange (Online) administration with PowerShell

Join our webinar to discover how PowerShell can transform your Exchange Online administration, making it more efficient and less time-consuming.

Whether you're a beginner or an experienced administrator, you'll learn practical tips and scripts to streamline your daily tasks, automate processes, and enhance your system's performance.

Simplify your workflow, improve your productivity, and unlock new capabilities with the power of PowerShell.

Don't miss out on this opportunity to take your Exchange Online management to the next level!

Exchange Online Englisch Website


In this webinar, we covered how to:

  • How to empower your service desk team with secure, PowerShell-driven mailbox management through an intuitive web interface.
  • Enable specific script execution without granting administrative permissions, ensuring a secure environment.
  • Simplify your PowerShell management with centralized scheduling and monitoring.
  • Boost your Exchange administration efficiency with our ready-to-use scripts, designed to streamline your processes and tasks.


If you couldn't attend the event, no problem:  


Request your recording!



Related links

Related posts

About the author: