Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Microsoft Exchange Server PowerShell Essentials

You're reading from   Microsoft Exchange Server PowerShell Essentials Leverage the power of basic Windows PowerShell scripts to manage your Exchange messaging environment

Arrow left icon
Product type Paperback
Published in Feb 2016
Publisher
ISBN-13 9781782176039
Length 210 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Biswanath Banerjee Biswanath Banerjee
Author Profile Icon Biswanath Banerjee
Biswanath Banerjee
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Getting Started with PowerShell 2. Learning Recipient Management FREE CHAPTER 3. Handling Distribution Groups 4. Exchange Security 5. Everything about Microsoft Exchange Policies 6. Handling Exchange Server Roles 7. Auditing and E-Discovery 8. Managing High Availability 9. Exploring EWS Managed API 10. Common Administration Tasks 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.
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image