Forum Discussion

robmo's avatar
robmo
Brass Contributor
Jan 07, 2022
Solved

How to use multiple tests in a switch statement

Hi,

I am working on a script that gets the CanonicalName for a device from a device and splits it up to determine the support region. I cannot figure out how to get multiple tests to work. If $splitCN[1] equals "Acapulco""Cozumel""Lazaro Cardenas""Mexico City""Pto Progresso""Veracruz", $SupportRegion should equal Mexico. I have tried several variations but it doesn't work so far. I know this is possible in other languages but I'm not sure on the PowerShell syntax. How do I accomplish this?

 

 

 

        "MEXICO.INT" {
            switch ($splitCN[1]) { 
                ("Acapulco","Cozumel","Lazaro Cardenas","Mexico City","Pto Progresso","Veracruz") {
                    $SupportRegion = "Mexico"
                    break
                }
           
                "Mazanillo" {
                    $SupportRegion = "ZLO"
                    break
                }
            
                "Tuxpan" {
                    $SupportRegion = "Tuxpan"
                    break
                }
            
            }
        }

 

 

 

2 Replies

Resources