Book Image

Microsoft Exchange Server PowerShell Essentials

By : Biswanath Banerjee
Book Image

Microsoft Exchange Server PowerShell Essentials

By: Biswanath Banerjee

Overview of this book

PowerShell has become one of the most important skills in an Exchange administrator's armory. PowerShell has proved its mettle so widely that, if you're not already starting to learn PowerShell, then you're falling behind the industry. It isn't difficult to learn PowerShell at all. In fact, if you've ever run commands from a CMD prompt, then you'll be able to start using PowerShell straightaway. This book will walk you through the essentials of PowerShell in Microsoft Exchange Server and make sure you understand its nitty gritty effectively. You will first walk through the core concepts of PowerShell and their applications. This book discusses ways to automate tasks and activities that are performed by Exchange administrators and that otherwise take a lot of manual effort. Microsoft Exchange PowerShell Essentials will provide all the required details for Active Directory, System, and Exchange administrators to help them understand Windows PowerShell and build the required scripts to manage the Exchange Infrastructure.
Table of Contents (17 chapters)
Microsoft Exchange Server PowerShell Essentials
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Switch statements


A Switch statement is used to check multiple conditions. It is equivalent to a series of If statements. The Switch statement lists each condition and an optional action. If a condition is true, the action is performed:

Syntax:

        Switch (<test-value>)
        {
            <condition> {<action>}
            <condition> {<action>}
        }

The Switch statement compares the value of 2 to each of the conditions listed. Once the test value matches the condition, the action is performed:

        PS> switch (2) 
         {
            1 {"It is one."}
            2 {"It is two."}
            3 {"It is three."}
            4 {"It is four."}
         } 
        It is two.

In the previous example, the value is compared to each condition in the list and there is a match for the value of 2. Let's take a look at the same example where we have added another condition that matches the value of 2:

        PS> switch (2) 
         {
            1 {"It is one."}
            2 {"It is two."}
            3 {"It is three."}
            4 {"It is four."}
            2 {"Two again."}
         } 
        It is two.
        Two again.

Using the Break statement, you can directly switch to stop the comparison after a match and terminate the switch statement:

        PS> switch (2) 
         {
            1 {"It is one."}
            2 {"It is two."; Break}
            3 {"It is three."}
            4 {"It is four."}
            2 {"Two again."}
         } 
        It is two.