Datasheet

Part I: PowerShell for Exchange Fundamentals
24
collection to the Set-User cmdlet along with the appropriate value for the Fax parameter you can
change the fax number quickly and easily on every user account using a single command line.
Commands that use multiple cmdlets and pipelines on a single line are often referred to as one - liners.
The following one - line command demonstrates the previous example for changing the fax number for
all users contained in the
Denver organizational unit:
[PS] C:\ > Get-User -OrganizationalUnit “CN=Denver,DC=exchangeexchange,DC=local” |
Set-User -Fax 555-1234
Whether there are 10 or 10,000 users in the organizational unit really does not matter in this example.
By collecting the user objects based on their organizational unit container with the first cmdlet, we are
able to modify the fax number on all users in bulk with the second cmdlet without additional complex
programming.
Filtering Objects
Not all cmdlets may provide parameters for filtering objects like the one shown in the previous example.
And though some cmdlets may provide a few filtering parameters, they may not provide a parameter
for the specific property you may need to use as a filter condition. That s when you need to become
familiar with the
Where-Object filter cmdlet.
Where-Object allows you to filter objects out of the command stream based on one or more test
conditions you specify in a script block. The test conditions are based on one or more of the objects
properties. Only the objects that meet the test conditions are passed on to the next command, while all
others are discarded. The most basic syntax of
Where-Object is easy to learn:
< command > | Where-Object { < test condition > } | < command >
Where and “?” are both shorthand alias names for the Where-Object cmdlet.
The test condition is an expression that resolves to either Boolean true or false. Only the objects that
resolve true when tested are passed down the pipeline to the next command. The syntax of the test
condition is made up of the following elements:
{ $_. < property name > < comparison operator > < value to test > < conjunction > $_. < property
name > < comparison operator > < value to test > ...}
The first element $_ is a special variable (called an automatic variable) and is used to refer to objects
in the pipeline stream. Using a technique called dot notation a property name is appended to the
$_ variable to refer to the specific object property to which the test applies. For example, $_.Identity
refers to an object ’ s
Identity property.
A comparison operator is used to set the condition of the test. Windows PowerShell supports a number
of named comparison operators. The most frequently used operators for comparing whole property
values are
eq (equals), ne (not equals), lt (less than), and gt (greater than). The like and notlike
operators are used to compare string values using wildcard rules. To see a complete list of all comparison
operators type
Get-Help about_Comparison_Operators at the command line.
c01.indd 24c01.indd 24 12/17/07 3:19:30 PM12/17/07 3:19:30 PM