15 Exchange Server PowerShell Commands Every Admin Should Know

Microsoft Exchange Server is a powerful email and collaboration platform widely used in enterprises worldwide. While the Exchange Admin Center provides a user-friendly graphical interface, many administrators prefer the flexibility and automation capabilities offered by PowerShell. PowerShell cmdlets allow you to perform a wide range of tasks, from managing mailboxes and distribution groups to configuring transport rules and monitoring server health. In this article, we’ll explore 15 essential Exchange Server PowerShell commands that every admin should have in their toolkit.

Get-Mailbox

The Get-Mailbox cmdlet is a versatile command that retrieves information about mailboxes in your Exchange organization. It allows you to filter mailboxes based on various criteria, such as mailbox type, database, or server. This cmdlet is particularly useful for gathering mailbox statistics, checking mailbox properties, and performing bulk operations.

Example:

# Get all mailboxes in the organization Get-Mailbox # Get mailboxes with a specific database Get-Mailbox -Database "DB01" # Get mailbox statistics Get-Mailbox -Identity "user@domain.com" | Select-Object DisplayName, DatabaseName, TotalItemSize

New-Mailbox

As the name suggests, the New-Mailbox cmdlet creates new mailboxes in your Exchange environment. It supports various mailbox types, including user mailboxes, room mailboxes, and shared mailboxes. You can specify mailbox properties, such as database, alias, and address book policies, during mailbox creation.

Example:

# Create a new user mailbox New-Mailbox -UserPrincipalName "user@domain.com" -Alias "user" -Database "DB01" -Name "John Doe" -OrganizationalUnit "ou=Users,dc=domain,dc=com" # Create a new room mailbox New-Mailbox -Room -Name "Conference Room" -Database "DB01" -EmailAddresses "confroom@domain.com"

Set-Mailbox

The Set-Mailbox cmdlet allows you to modify the properties of existing mailboxes. You can change mailbox settings, such as mailbox quotas, retention policies, and delivery options. This cmdlet is essential for managing mailbox configurations and ensuring compliance with organizational policies.

Example:

# Set mailbox quota Set-Mailbox -Identity "user@domain.com" -IssueWarningQuota 20GB -ProhibitSendQuota 24GB -ProhibitSendReceiveQuota 25GB # Enable mailbox auditing Set-Mailbox -Identity "user@domain.com" -AuditEnabled $true

Add-MailboxPermission

The Add-MailboxPermission cmdlet grants permissions to users or security groups to access a specific mailbox. This is particularly useful for shared mailboxes or when delegating access to another user’s mailbox for administrative or support purposes.

Example:

# Grant full access to a user's mailbox Add-MailboxPermission -Identity "user@domain.com" -User "admin@domain.com" -AccessRights FullAccess -InheritanceType All # Grant send-as permission to a distribution group Add-MailboxPermission -Identity "shared@domain.com" -User "DG-Sales@domain.com" -AccessRights SendAs

Get-MailboxStatistics

The Get-MailboxStatistics cmdlet retrieves detailed statistics about mailboxes, including item counts, mailbox sizes, and last access times. This information is invaluable for monitoring mailbox usage, identifying potential issues, and planning storage requirements.

Recommended For You: Optimize Hyper-V Storage with PowerShell: Deduplication & More

Example:

# Get mailbox statistics for all mailboxes Get-MailboxStatistics # Get mailbox statistics for a specific mailbox Get-MailboxStatistics -Identity "user@domain.com"

New-DistributionGroup

The New-DistributionGroup cmdlet creates new distribution groups in your Exchange organization. Distribution groups are essential for email communication within teams or departments. You can create various types of distribution groups, including security groups and dynamic distribution groups.

Example:

# Create a new distribution group New-DistributionGroup -Name "Sales Team" -Alias "sales" -MemberJoinRestriction Closed -MemberDepartRestriction Closed # Create a new dynamic distribution group New-DynamicDistributionGroup -Name "West Coast Employees" -RecipientFilter "Company -eq 'Contoso' -and StateOrProvince -eq 'CA,OR,WA'"

Add-DistributionGroupMember

The Add-DistributionGroupMember cmdlet allows you to add members (users or other distribution groups) to an existing distribution group. This cmdlet is crucial for managing group memberships and ensuring that the right individuals receive relevant communications.

Example:

# Add a user to a distribution group Add-DistributionGroupMember -Identity "Sales Team" -Member "user@domain.com" # Add multiple users to a distribution group $users = "user1@domain.com", "user2@domain.com", "user3@domain.com" Add-DistributionGroupMember -Identity "Sales Team" -Members $users

Get-TransportRule

The Get-TransportRule cmdlet retrieves information about transport rules configured in your Exchange organization. Transport rules are powerful tools that allow you to apply actions to incoming or outgoing messages based on specific conditions. This cmdlet helps you review and manage your transport rules.

Example

# Get all transport rules Get-TransportRule # Get a specific transport rule Get-TransportRule -Identity "Block Attachments"

New-TransportRule

The New-TransportRule cmdlet creates new transport rules in your Exchange environment. Transport rules can perform various actions, such as blocking or redirecting messages, adding disclaimers, or applying message classifications based on predefined conditions.

Example

# Create a transport rule to block attachments with specific file types New-TransportRule -Name "Block Attachments" -AttachmentIsUnsupported "(?i)\.ade|\.adp|\.bat|\.chm|\.cmd|\.com|\.cpl|\.exe|\.hta|\.ins|\.isp|\.js|\.jse|\.lib|\.lnk|\.mde|\.msc|\.msp|\.mst|\.pif|\.scr|\.sct|\.shb|\.sys|\.vb|\.vbe|\.vbs|\.vxd|\.wsc|\.wsf|\.wsh" -RejectMessageReasonText "Attachment blocked due to security policy" # Create a transport rule to apply a disclaimer to outgoing messages New-TransportRule -Name "Disclaimer" -SentToScope "InOrganization" -ApplyHtmlDisclaimerLocation "Append" -HtmlDisclaimerText "

This message is confidential and intended for the recipient only.

"

Test-MAPIConnectivity

The Test-MAPIConnectivity cmdlet tests the MAPI connectivity between a client and an Exchange server. This cmdlet is particularly useful for troubleshooting Outlook connectivity issues and identifying potential problems with mailbox access.

Example

# Test MAPI connectivity for a specific mailbox Test-MAPIConnectivity -Identity "user@domain.com" # Test MAPI connectivity for all mailboxes on a specific database Get-Mailbox -Database "DB01" | Test-MAPIConnectivity

Get-MessageTrackingLog

The Get-MessageTrackingLog cmdlet retrieves message tracking logs from your Exchange environment. These logs provide detailed information about the delivery status of email messages, including sender, recipient, and any errors or delays encountered during the delivery process.

Example

# Get message tracking logs for a specific sender Get-MessageTrackingLog -Sender "user@domain.com" # Get message tracking logs for a specific recipient Get-MessageTrackingLog -Recipients "user@domain.com"

Get-TransportService

The Get-TransportService cmdlet retrieves information about the transport services running on your Exchange servers. Transport services are responsible for handling message delivery and routing within your organization. This cmdlet helps you monitor the status of these services and identify potential issues.

Recommended For You: Migrate Virtual Machines Between Hyper-V Hosts with PowerShell

Example

# Get transport services on all Exchange servers Get-TransportService # Get transport services on a specific server Get-TransportService -Server "EX01"

Set-TransportConfig

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

Example

# Set maximum message size limit Set-TransportConfig -MaxReceiveSize 25MB -MaxSendSize 25MB # Add an accepted domain Set-TransportConfig -AddressSpacesEnabled $true -AddressSpacesCostHybridRemoteGateway "Internet" -AddressSpacesInternal "contoso.com"

Get-MailboxDatabase

The Get-MailboxDatabase cmdlet retrieves information about mailbox databases in your Exchange environment. This cmdlet provides valuable insights into database properties, such as database size, mounted server, and mailbox counts.

Example

# Get all mailbox databases Get-MailboxDatabase # Get a specific mailbox database Get-MailboxDatabase -Identity "DB01"

Start-ManagedFolderAssistant

The Start-ManagedFolderAssistant cmdlet initiates the Managed Folder Assistant process, which applies retention policies to mailboxes. Retention policies help organizations comply with legal and regulatory requirements by automatically deleting or archiving older items based on predefined rules.

Example

# Start the Managed Folder Assistant for a specific mailbox Start-ManagedFolderAssistant -Identity "user@domain.com" # Start the Managed Folder Assistant for all mailboxes Get-Mailbox | Start-ManagedFolderAssistant

Conclusion:

PowerShell cmdlets provide Exchange administrators with a powerful toolset for managing and automating various tasks within their Exchange environment. The 15 commands covered in this article are essential for mailbox management, distribution group administration, transport rule configuration, message tracking, and server monitoring. By mastering these cmdlets, administrators can streamline their workflows, ensure compliance, and maintain a healthy and efficient Exchange infrastructure.

FAQs

  1. Can I use PowerShell to manage Exchange Online (Office 365) environments?Yes, the Exchange Online PowerShell module allows you to manage your Exchange Online environment using PowerShell cmdlets. You can connect to Exchange Online using the Connect-ExchangeOnline cmdlet.
  2. How can I automate repetitive tasks using PowerShell? PowerShell scripts allow you to automate repetitive tasks by combining multiple cmdlets and adding logic and control structures. You can create scripts to perform bulk operations, schedule recurring tasks, or automate complex workflows.
  3. What are the prerequisites for running Exchange PowerShell cmdlets? To run Exchange PowerShell cmdlets, you need to have the Exchange Management Shell installed on your machine. Additionally, you must have the appropriate permissions and roles assigned to your account to perform the desired tasks.
  4. Can I use PowerShell to manage hybrid Exchange environments? Yes, PowerShell cmdlets can be used to manage hybrid Exchange environments, which combine on-premises Exchange servers with Exchange Online. You can use the appropriate cmdlets for each environment, or use the Exchange Online Remote PowerShell Module to manage both environments from a single PowerShell session.
  5. How can I learn more about Exchange PowerShell cmdlets? Microsoft provides extensive documentation and resources for Exchange PowerShell cmdlets. You can refer to the Exchange Server PowerShell documentation [link], Exchange Online PowerShell documentation [link], and various blogs and forums dedicated to Exchange administration.

If you'd like to learn more, consider these helpful resources: