Something like this? I'm comparing the realative path only(path from $loc) in case $loc
includes one of the foldernames to ignore.
$loc = "C:\tools\scripts\myscripts\"
$files = Get-ChildItem -Path $loc -Recurse -Exclude *.docx, *.xlsx | ? { !$_.PSIsContainer -and !($_.FullName.Replace($loc,"") -like "*scripts\*") }
Multiple folders(this got ugly):
#Don't include "\" at the end of $loc - it will stop the script from matching first-level subfolders
$loc = "C:\tools\scripts\myscripts"
$ignore = @("testfolder1","testfolder2");
$files = Get-ChildItem -Path $loc -Recurse -Exclude *.docx, *.xlsx | ? { !$_.PSIsContainer } | % { $relative = $_.FullName.Replace($loc,""); $nomatch = $true; foreach ($folder in $ignore) { if($relative -like "*\$folder\*") { $nomatch = $false } }; if ($nomatch) { $_ } }