【发布时间】:2013-07-22 20:13:28
【问题描述】:
有没有办法在 foreach 循环中捕获和保存坏名?我有以下内容:
$CollectionName = "Import Test"
$PCName = Import-Csv "C:\Powershell\import_test.csv"
foreach($computer in $PCName) {
Add-CMDeviceCollectionDirectMembershipRule -CollectionName $CollectionName -ResourceID $(Get- CMDevice -Name $computer.computername).ResourceID
}
我想做的是,如果 csv 中有一个错误的名称,那么不要显示我目前得到的“无法验证参数”错误,而是将失败的名称输出到一个文本文件。
谢谢
【问题讨论】:
-
你玩过
-ErrorAction吗?另外,这里有一个关于在 powershell 中捕获异常的页面:stackoverflow.com/questions/4691874/…
标签: powershell