Manage Learn to apply best practices and optimize your operations.

Exchange PowerShell commands for faster mailbox management

Whether you have 10 or 10,000 mailboxes, working with Exchange PowerShell commands in readily available scripts can ease mailbox administrative tasks.

Just because Exchange mailbox management is a constant in the administrator's life doesn't mean it has to be a...

chore.

Most Exchange administrators manage mailboxes on a regular basis. This workload can add up when you factor in the different types of mailboxes: regular user mailboxes, shared or equipment mailboxes, and public folder mailboxes. Building scripts based on Exchange PowerShell commands, or modifying scripts from the Microsoft Script Center, reduces the time and effort to manage multiple Exchange mailboxes.

Use Exchange PowerShell commands to manage mailbox lifecycles

Administrators usually handle mailbox lifecycle tasks either through the Exchange admin center or through an identity management product. The latter provisions, modifies or removes a user from Active Directory, the related mailbox and its mailbox properties.

Where Office 365 offers many reports, Exchange on-premises customers often resort to creating their own reporting scripts.

An identity management offering may support other products, such as Microsoft Skype for Business or SharePoint. Because provisioning often deals with a single to a few entries, and is company-specific, the administrator will often create custom provisioning scripts from Exchange PowerShell commands. For example, administrators will combine the New-Mailbox cmdlet and additional settings through other cmdlets to configure access options and the user's group memberships. Those scripts often use a comma-separated values (CSV) file managed with Excel. Below is a simple example showing how a PowerShell script named CreateUsers.ps1 adds mailboxes based on users from the NewUsers.csv file.

NewUsers.csv
Alias,DisplayName,UPN,Email,Country
"Philip","Philip Mortimer","philip@contoso.com","philip@contoso.com,"UK"
"Francis","Francis Mortimer","francis@contoso.com","francis@contoso.com","UK"

CreateUsers.ps1
$pw= Read-Host "Enter initial password to use" –AsSecureString
Import-CSV .\NewUsers.csv | ForEach {New-Mailbox -Alias $_.alias -Name $_.name -userPrincipalName $_.UPN -OrganizationalUnit "ou=Users,ou=$($_.Country),dc=contoso,dc=com" -Password $pw}

Administrators can modify these scripts to incorporate additional configuration steps using conditions, such as assigning group memberships based on country, hosting the mailbox in a specific database and assigning policies. With enough effort and Powershell acumen on the administrator's part, a simple script can evolve into a full custom provisioning script tailored to the needs of the organization.

Administrators who prefer a graphical user interface can use a variety of third-party offerings to automate the account creation process, such as Zohno Inc.'s Z-Hire.

Execute changes to multiple objects

Administrators save time and avoid a lot of manual work when they modify multiple objects with Exchange PowerShell commands. For example, to remove all secondary SMTP addresses for an expired domain name, fabrikam.com, from existing mailboxes, it's as simple as:

Get-Mailbox -ResultSize Unlimited | % { Set-Mailbox –Identity $_.Identity –EmailAddresses ($_.EmailAddresses | Where $_.ProxyAddressString –cnotlike 'smtp:*@fabrikam.com')}

Generate mailbox reports

As part of a preventative maintenance routine, Exchange administrators regularly check on the mailbox population. Where Office 365 offers many reports, on-premises administrators will often resort to using Exchange PowerShell commands to create their own reporting scripts.

Before building a new report, see what is available; many scripts allow for tweaking in their license for use.

The most frequently used Exchange reports an administrator needs are:

  • Exchange Environment Report shows a basic overview of the Exchange environment and provides details, such as which Exchange product builds are deployed, and how the mailbox population is distributed over the various Exchange servers and databases. Get the script here.
  • Get-MailboxReport.ps1 shows the mailbox population and returns statistics on mailbox and archive size, quota usage statistics, and management information such as when a mailbox was last accessed and by whom. The script, available here, outputs in CSV format, which is convenient for future filtering and processing in Excel.
  • Report-MailboxPermissions.ps1 generates an HTML report on mailbox permissions, such as which user has full access to which mailbox, and which user has send-as or send-on-behalf permissions for a certain user. The script is available here.
  • Get-MailboxAuditLoggingReport.ps1 creates an audit logging report for an auditing-enabled mailbox, showing types of access -- creations, deletions, send as -- and which part of the mailbox was accessed. Access it here.

Next Steps

Remove a stubborn mailbox database in Exchange

Use the Search-Mailbox cmdlet to its full potential

How to reveal a missing public folder after an Exchange migration

This was last published in November 2016

Dig Deeper on Microsoft Exchange Server Scripts and Programming

PRO+

Content

Find more PRO+ content and other member only offers, here.

Join the conversation

1 comment

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

What are some particularly useful Exchange PowerShell scripts you have used to manage mailboxes?
Cancel

-ADS BY GOOGLE

SearchWindowsServer

SearchEnterpriseDesktop

SearchCloudComputing

SearchSQLServer

Close