How to use wildcards with directories in PowerShell's Get-ChildItem -Exclude cmdlet
I haven't seen the exclude parameter working with directories either.
You could try piping into Where-Object. That is,
Get-ChildItem -Recurse *.pdb | Where-Object {$_.FullName -notMatch "folder2"}
gci "C:\Root" -Recurse | Where-Object {$_.FullName -notlike "*Folder2\*.pdb*"} | Export-CSV "C:\Root\Export.csv" -NoType
Tried, tested & one liner :-). This works as I have copied your folder & file structure to replicate. Sorry about it being a few years late, however.
Feel free to tweak the code to your needs, obviously.
OhadH's answer is almost there.
You can use
Get-ChildItem -Recurse | Where-Object {$_.FullName -notmatch "folder2" -or $_.Name -notlike "*.pdb" }
or
Get-ChildItem -Recurse | ? {$_.FullName -notlike "*folder2*" -or $_.Name -notlike "*.pdb" }
It depends on where your folder2 is located. But I think you got the idea.
I hate to say it, but PowerShell is not any convenient as Bash or other shells.