BACKGROUND IMAGE: iSTOCK/GETTY IMAGES
In this tip, Microsoft Exchange expert Brien Posey explains the Set command's role in the Exchange Management Shell (EMS), and how to use it to configure an Exchange 2007 mailbox to block specific senders.
Using the Exchange Management Shell is recommended to write a script that performs configuration tasks automatically or to manipulate settings that aren't exposed through Exchange Server 2007's GUI. Although managing Exchange from the command line can be intimidating, understanding how EMS' command syntax works can alleviate any fears. Once you understand Exchange Management Shell basics, the next step is to learn how to set various parameters using the Set command.
The Set command
Exchange Management Shell commands are entered in a verb-noun format. The verb tells Exchange Server what action you want to perform, and the noun tells Exchange on what object you want to perform that action. When you need to assign a value to an individual property, use the Set verb. However, the Set command doesn't do anything on its own; it must be paired with a noun.
It's helpful to know which command you will use to accomplish a specific task, but it's not required. Exchange Server offers some help with this, if you know where to look. Because the Set command is commonly used to assign a value to a specific attribute, one way to get help determining which command to use is to enter Get-Help Set-*.
This command instructs Exchange Server 2007 to show you all commands that are valid when used in conjunction with the Set verb. While this results in a long list of commands, it gives you a starting point by listing the name of each command and a brief synopsis of what it does.
If none of the commands listed describe what you want to accomplish, you may want to take another look at the big picture. For example, if you wanted to configure Exchange to reject messages from certain recipients, there isn't a Set command that does this specifically. Messages often are accepted or rejected as they pass through the recipient filter. If you look again at the list of available commands, you'll see the Set-RecipientFilterConfig command.
The ability to block specific recipients is a function of the Set-RecipientFilterConfig command. To block specific recipients, you must know how to use the various parameters associated with this command. Exchange Server will list valid commands and explanations of command actions, but it doesn't give you the command's full syntax. Fortunately, you can append the Set-RecipientFilterConfig command to the Get-Help command, prompting Exchange to display the command's full syntax. The full command for this is:
This command gives the full syntax for the Set-Mailbox command, which can be fairly long. However, the syntax that's displayed shows you how to configure a mailbox to block messages from a particular recipient.
After viewing the command's full syntax, you should be able to block the recipients. For example, if you wanted to block the user Brien@contoso.com, the command would be:
Set-RecipientFilterConfig –BlockedRecipients "Brien@contoso.com"
To verify that the command has worked, enter a variation that uses Get instead of Set:
The name of the recipient that you entered should appear on the list of blocked recipients.
We used the Set command to associate a value with a property. While working with the Exchange Management Shell, you'll typically use this same technique, even if the value you're setting is unrelated to recipient filtering.
Standard and multi-valued properties
Exchange Server 2007 allows for two different types of properties: standard and multi-valued. A standard property involves assigning a value to an attribute. A multi-valued property is an attribute that can have several values associated with it.
The BlockedRecipients parameter is a multi-valued property, because the list of blocked recipients must be able to store more than one recipient's email address.
With multi-valued properties, you cannot use the Set command as we did previously to add another value. If I wanted to add Posey@contoso.com to the list of blocked recipients, for example, I would enter:
Set-RecipientFilterConfig –BlockedRecipients "Posey@contoso.com"
- How to use Exchange Management Shell's Filter command
- Control query results with Exchange Management Shell's Format command
- How to test Exchange Management Shell commands
- The Exchange Management Shell for Exchange Server 2007
When I enter the Get-RecipientFilterConfig command, the first blocked recipient's email address has been overwritten. To compile a list of values for the property, use the variables. The basic idea is to define a variable, and then use the Get command to populate the variable. You then can use the Set command to add an additional value to the variable.
In Exchange Server 2007, variables are defined with a dollar sign. A variable named List would be called $List. To assign the contents of the RecipientFilterConfig to a variable named List, use this command:
$List = Get-RecipientFilterConfig
Suppose that you wanted to add the email address BP@contoso.com to the list of blocked recipients. First, you must manipulate the variable to contain the new name. The following command adds the new email address to the list of email addresses currently associated with the variable:
$List.BlockedRecipients += "BP@contoso.com"
Keep in mind that we haven't updated the blocked recipients list; we've only updated the variable. We must now update the blocked recipients list with the variable's contents. To do so, use the Set command as shown here:
Set-RecipientFilterConfig –BlockedRecipients $List.BlockedRecipients
Now we can use the Get-RecipientFilterConfig command to verify that the operation was performed successfully. When entering this command, the Blocked Recipients list should show multiple entries. Figure 1 shows these commands.
About the author: Brien M. Posey, MCSE, has previously received Microsoft's MVP award for Microsoft Exchange, Windows Server and Internet Information Server (IIS). Brien has served as CIO for a nationwide chain of hospitals and was once responsible for the Department of Information Management at Fort Knox. As a freelance technical writer, Brien has written for Microsoft, TechTarget, CNET, ZDNet, MSD2D, Relevant Technologies and other technology companies. You can visit Brien's personal website at www.brienposey.com.
Do you have comments on this tip? Let us know.
Please let others know how useful this tip was via the rating scale below. Do you know a helpful Exchange Server, Microsoft Outlook or SharePoint tip, timesaver or workaround? Email the editors to talk about writing for SearchExchange.com.