user25407 user25407 - 2 months ago 12
PowerShell Question

exclude multiple folder using gci

I have 2 subfolders 'PS Logs', 'Executables' in the root directory "C:\Temp\". How to exclude them using gci. I am doing the crude way where I exclude all the underlying files in these sub-folder.

Get-ChildItem -Path "C:\Temp\" -recurse -exclude *.*


Try this

Get-ChildItem C:\temp -Recurse | Where-Object {!($_.FullName -match 'PS Logs') -and !($_.FullName -match 'Executables')} | Select-Object -ExpandProperty Fullname