「PowerShell入門」switch文で条件に一致するかどうか判定サンプル

2020年12月21日

書式
switch(数値または文字列)
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$cft = 105
$target="cft"
#基本switch文 数値
switch ($cft) {
100 {
echo "AA01"
}
105 {
echo "BB02"
}
110 {
echo "CC03"
}
}
#文字列
switch($target){
"A001"{
echo "value is A001"
}
"cft"{
echo "value is changfatun"
}
"B002"{
echo "value is B002"
}
}
$cft = 105 $target="cft" #基本switch文 数値 switch ($cft) { 100 { echo "AA01" } 105 { echo "BB02" } 110 { echo "CC03" } } #文字列 switch($target){ "A001"{ echo "value is A001" } "cft"{ echo "value is changfatun" } "B002"{ echo "value is B002" } }
$cft = 105
$target="cft"
#基本switch文 数値
switch ($cft) {
    100 {
        echo "AA01"
    }
    105 {
        echo "BB02"
    }
    110 {
        echo "CC03"
    }
}
#文字列
switch($target){
       "A001"{
             echo "value is A001"
       }
       "cft"{
             echo "value is changfatun"
       }
       "B002"{
             echo "value is B002"
       }
      
}

実行結果
> .\test.ps1
BB02
value is changfatun

PowerShell

Posted by arkgame