如何从CSV输入调用PowerShell开关案例

时间:2017-11-06 18:09:11

标签: powershell csv

我有一个带有switch语句的PowerShell脚本,我正在尝试将CS​​V输入导入脚本以及将在switch case语句中使用的必需变量。其中一行将不会调用开关盒。

enter image description here

Import-Csv $path
switch ($_.caseid) {
    1 {
        # task goes here
    }
    2 {
        # task goes here
    }
    3 {
        # task goes here
    }
}

如果数字匹配,它应执行相应的块并从CSV中删除执行的行,如果该字段为空或值不正确,则应忽略该行并转到其他行。

1 个答案:

答案 0 :(得分:1)

Import-Csvswitch语句与ForEach-Object

相关联
Import-Csv $path | ForEach-Object {
    switch ($_.caseid) {
        1 {
            # task goes here
        }
        2 {
            # task goes here
        }
        3 {
            # task goes here
        }
    }
}