I'm trying to get child items of a folder recursively. However the folder contains noise files and folder (actually, this is a Visual Studio project folder).
Here what I have:
$root = Get-Item C:\Projects\MyProject
$allItems = Get-ChildItem $root -Recurse -exclude "**\pkgobj\*"
However, $allItems
still contains files and folder matching the paths.
What I did wrong?
To be more precise, I want to get both folders and files, but not the specified folder, and any of its descendant.
I also tried:
foreach($item in $allItems){
if($item.FullName -notmatch "pkgobj") {
Write-Host -ForegroundColor Green $item.FullName.Replace($root,'')
}
}
But no more success