Using flow control statements

Flow control statements are used in the shell to run one or more commands based on the result of a conditional test. You can use the If statement to test one or more conditional statements, and you can also use switch statements when multiple If statements would otherwise be required. This recipe will show you how to control the flow of execution that your scripts will use in the shell.

How to do it...

Let's store the status of a database called DB1 in a variable that can be used to perform some conditional checks:

$DB1 = Get-MailboxDatabase DB1 -Status

When using an If statement, you use the If keyword followed by an expression enclosed in parenthesis that performs a conditional check. If the expression is evaluated ...

Get Microsoft Exchange 2010 PowerShell Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.