O'Reilly logo

Microsoft Exchange Server 2013 PowerShell Cookbook - Second Edition by Mike Pfeiffer, Jonas Andersson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required