Can't exclude a directory pattern recursively
Took me a moment to understand the issue. Its a tricky one.
-exclude
only applies to basenames of items (i.e. myfile.txt
), not the fullname
(i.e. C:\pkgobj\myfile.txt
) which you want. So you can't use exclude here.
But there is a workaround using Fullname
and -notlike
$root = "C:\Projects\MyProject"
$allitems = Get-ChildItem $root -Recurse | Where {$_.FullName -notlike "*\pkgobj\*"}