在Powershell中处理foreach对象循环中的过长路径时出错

时间:2016-09-19 11:23:19

标签: powershell error-handling

我目前有这个:

Get-ChildItem $somelongpath -Recurse -ErrorVariable MyError -ErrorAction Stop  | where {$_.PSIsContainer} | ForEach-Object{
     if($MyError){
        Write-Host "Don't do it"
     } else {
        Write-Host "Yay!"
     }
}

假设$somelongpath是超过260限制的路径,因此get-childitem应该收到错误并打印"不要这样做"。但它没有...发生了什么?

0 个答案:

没有答案