I have a super annoying problem, where I am basically doing the following:
Get-ChildItem $rootPath -Recurse |
Where {$_.psiscontainer} |
Get-Acl | % {
Write-Host "Doing some stuff here"
}
But I occasionally get an error when calling Get-Acl
saying that I don't have access.
That is fine, I can just catch the error and continue right?
So i tried
Get-ChildItem $rootPath -Recurse |
Where {$_.psiscontainer} |
try {
Get-Acl | % {
Write-Host "Doing some stuff here"
}
} catch {Write-Host "error"}
But now I get
the term 'try' is not recognized
Which is unbelievably unhelpful, since try
definitely is a command in PowerShell...
Next I tried to split the command out like so
$folders = Get-ChildItem $rootPath -Recurse | Where {$_.psiscontainer}
foreach ($folder in $folders) {
try {
Get-Acl | % {
Write-Host "Doing some stuff here"
}
} catch {write-host "error"}
}
Now i'm getting
Get-childitem : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
WHY? And how am I supposed to check which folder is failing?