0

I currently have this:

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

Say that $somelongpath is a path that exceeds the 260 limit and therefore get-childitem should receive an error and print "Don't do it". But it doesn't... What is happening?

  • What results are you getting from your code? – Jimbo Sep 19 '16 at 11:52
  • @Jimbo I get a big red warning that the path is too long. – Benjamin S. Sorterup Sep 19 '16 at 12:27
  • your erroraction says "Stop", so that is what it is doing. Try silentlycontinue – Jimbo Sep 19 '16 at 12:50
  • @Jimbo Then I doesn't print anything. – Benjamin S. Sorterup Sep 19 '16 at 12:56
  • @AnsgarWiechers How? I'm not trying to work around it I'm trying to report an error when it occurs and otherwise continue working if it doesn't. – Benjamin S. Sorterup Sep 19 '16 at 13:25
  • 2
    If you want to see the paths that are causing any errors then your code will not do that - by using silentlycontinue or stop the rest of your code never sees any errors. To see all folders, regardless of path size, and to take action if the path exceeds 260, then check out "get-folderitem" by Boe Prox - https://learn-powershell.net/2013/04/01/list-all-files-regardless-of-260-character-path-restriction-using-powershell-and-robocopy/ – Jimbo Sep 19 '16 at 14:09

0 Answers0