Managing Exchange Server 2010 with PowerShell
- Jun 20, 2011
The Exchange Management Shell (EMS) builds on Windows PowerShell 2.0 and gives you a wealth of additional tools you can use to manage Microsoft Exchange 2010.
If you manage a Microsoft Exchange Server 2010 environment, you probably do a lot of your work in the Exchange Management Console. You can use this graphical user interface (GUI) to complete most of your tasks, but if you master some of the commands in the EMS, you’ll find you can complete many of your tasks more quickly and easily.
For example, the GUI often only allows you to work on a single object at a time. With the EMS, you can modify settings for individual mailboxes, all the mailboxes in an OU, all the mailboxes on a server, all the mailboxes in a database, or even all the mailboxes within an organization.
Setting the Warning Quota
Most organizations set limits on the size of user mailboxes. The warning quota sets a threshold for mailbox size, and Exchange sends a warning message to the user when the mailbox reaches the threshold.
Sometimes you want everyone in the organization to have the same warning quota. Other times, you may want to have different quotas set for different groups of users, such as users in an OU, database, or server. If you use the GUI, you’re limited on how you can set this quota. However, if you use PowerShell, you have many more capabilities.
The following examples show you the syntax to configure the warning quota for mailboxes at different levels of your Exchange organization.
Set the Warning Quota for a Single Mailbox
You probably won’t set the warning quota for an individual user with PowerShell. However, it’s useful to understand the basic cmdlet before expanding it to modify multiple users.
The basic syntax of the Set-Mailbox cmdlet is:
Set-Mailbox -Identity UserName -IssueWarningQuota size -UseDatabaseQuotaDefaults $boolean value
The -Identity switch identifies the name of the user that owns the mailbox. The -IssueWarningQuota switch configures the warning quota and accepts an integer followed by KB, MB, or GB as sizes (without a space). For example, if you want to set the warning quota to 500 MB, the value of size is 500MB or if you want to set it to 1 GB, the value of size is 1GB. The $boolean parameter identifies if the user will inherit the quota values set on the database. This value is set to $false when configuring individual settings so that the user setting overrides the database setting.
The following cmdlet will set the warning quota for a user named Darril to 500 MB:
Set-Mailbox -Identity Darril -IssueWarningQuota 500MB -UseDatabaseQuotaDefaults $boolean $false
There is much more you can do with the Set-Mailbox cmdlet. However, the focus here is only on showing how you can use the cmdlet to configure a setting, and then expand that knowledge to configure multiple settings.
Set the Warning Quota for All Users in an OU
If you’re tasked with reconfiguring the warning quota for all the users within an OU, you probably don’t want to do it manually for all the users. Instead, you can use the Get-Mailbox cmdlet to retrieve a list of mailboxes in an OU, and then pipe the results to the Set-Mailbox cmdlet. This following command shows the basic syntax:
Get-Mailbox -OrganizationalUnit OUname | Set-Mailbox -IssueWarningQuota size -UseDatabaseQuotaDefaults $boolean value
In this command, the Get-Mailbox cmdlet is first used to retrieve all the mailboxes within an OU. The pipe command (|) then directs PowerShell to send the output of the Get-Mailbox cmdlet to the following cmdlet (Set-Mailbox). Notice that the Set-Mailbox cmdlet doesn’t need the -Identity switch used to configure the setting for a single user. Instead, the Set-Mailbox cmdlet operates on all the mailboxes returned from the Get-Mailbox cmdlet.
If you wanted to set the warning quota for all mailboxes in the Sales OU to 500 MB, you’d use this command:
Get-Mailbox -OrganizationalUnit Sales | Set-Mailbox -IssueWarningQuota 500MB -UseDatabaseQuotaDefaults $boolean $false
Set the Warning Quota for All Users in a Database
You can set the warning quota for all users in a database using the same technique used to set the quota for all users in an OU. Here’s the basic syntax:
Get-Mailbox -Database DatabaseName | Set-Mailbox -IssueWarningQuota size -UseDatabaseQuotaDefaults $boolean value
Notice that the Get-Mailbox cmdlet has been modified to retrieve mailboxes in a database using the -Database switch. The result is piped to the Set-Mailbox cmdlet, just as it was piped in the previous example configuring all the mailboxes in an OU.
The following command will set the warning quota for all mailboxes in the database named SalesDB to 500 MB:
Get-Mailbox - Database SalesDB | Set-Mailbox -IssueWarningQuota 500MB -UseDatabaseQuotaDefaults $boolean $false
Set the Warning Quota for All Users on a Server
If you understand the commands to configure all the mailboxes in an OU or database, it becomes trivial to do the same thing for all mailboxes on a server. Here’s the basic syntax:
Get-Mailbox -Server ServerName | Set-Mailbox -IssueWarningQuota size -UseDatabaseQuotaDefaults $boolean value
The only thing that’s changed is in the Get-Mailbox cmdlet. The -Server switch is added with the ServerName parameter to identifythe name of the mail server.
If you wanted to set the warning quota for all mailboxes on a server named Mail1 to 500 MB, you could use the following command.
Get-Mailbox - Server Mail1 | Set-Mailbox -IssueWarningQuota 500MB -UseDatabaseQuotaDefaults $boolean $false
Set the Warning Quota for All Users in an Organization
This last example shows the syntax to configure this setting for all the users in the Exchange organization. Here’s the basic syntax:
Get-Mailbox | Set-Mailbox -IssueWarningQuota size -UseDatabaseQuotaDefaults $boolean value
Notice the Get-Mailbox cmdlet doesn’t include any switches to filter the output. Instead, it retrieves a list of all the mailboxes. As before, the output is piped to the Set-Mailbox cmdlet. Here’s the full command:
Get-Mailbox | Set-Mailbox -IssueWarningQuota 500MB -UseDatabaseQuotaDefaults $boolean $false
Use the Power with Care
While the PowerShell cmdlets included with EMS provide you with a great deal of power, it’s worth mentioning these should be used with care. You can quickly modify multiple objects within your organization saving you countless hours of tedium since you won’t have to do the tasks manually. However, if you make unwanted changes, it can just as easily result in countless hours of troubleshooting to get your system back to normal.
Testing is very important. The previous examples showed how to configure the warning quota for a single mailbox and multiple mailboxes. If you want to use these examples to modify a different setting, test your cmdlet on a single mailbox first. Once you’re satisfied with the result, expand the command to modify multiple mailboxes.
You can modify the results of the Get-Mailbox cmdlet using wildcards, the -filter switch, or by piping the results to a where clause. If you do, it’s worth your time to execute the Get-Mailbox cmdlet on its own to see the result before combining it with the Set-Mailbox cmdlet.
EMS is Much More than Two Cmdlets
While this article partially covered two EMS cmdlets (Get-Mailbox and Set-Mailbox), it’s important to realize that there is much more. Cmdlets are available to help with deployments, disaster recovery, recipient objects, roles, and much more. Additionally, these examples didn’t even show everything you can do with the Get-Mailbox and Set-Mailbox cmdlets. I’m betting you know this, but you can set much more than just the warning quota with the Set-Mailbox cmdlet.
However, you don’t have to master all of PowerShell and the EMS commands to use them. If you find a cmdlet gem that you like, you can use it to automate some administrative tasks without the need to master all of PowerShell.
Exchange Server 2010 Portable Command Guide
The information in this article was derived from the Exchange Server 2010 Portable Command Guide: MCTS 70-662 and MCITP 70-663 by Richard Robb and Darril Gibson published in June 2011. This book lists many of the common commands needed to pass the listed exams and commands regularly used on the job. It isn’t a massive tome including all the commands and switches you can possibly use, but instead is a portable take-anywhere guide to show you just what you need in your day-to-day administrative tasks.