Forum Discussion
robmo
Jan 07, 2022Brass Contributor
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 $split...
- Jan 07, 2022You can use script blocks, for example:
switch ("Cozumel") {
{$_ -in @("Acapulco","Cozumel","Lazaro Cardenas","Mexico City","Pto Progresso","Veracruz")} {
"Mexico"
break
}
}
Refer to the documentation for more info/examples: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_switch?view=powershell-7.2
VasilMichev
Jan 07, 2022MVP
You can use script blocks, for example:
switch ("Cozumel") {
{$_ -in @("Acapulco","Cozumel","Lazaro Cardenas","Mexico City","Pto Progresso","Veracruz")} {
"Mexico"
break
}
}
Refer to the documentation for more info/examples: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_switch?view=powershell-7.2
switch ("Cozumel") {
{$_ -in @("Acapulco","Cozumel","Lazaro Cardenas","Mexico City","Pto Progresso","Veracruz")} {
"Mexico"
break
}
}
Refer to the documentation for more info/examples: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_switch?view=powershell-7.2
- robmoJan 08, 2022Brass ContributorHi Vasil,
Your suggestion was able to get my code working. Thank you for taking the time to look at this!
Rob