I am trying to filter through a directory tree for certain folders and files, on each level of the sub folders, there are some folders I would like to ignore, so I would like to create an "ignore group", the search process will start from top level of the folder tree recursively, any name in that "ignore group" will be skipped.
The code below is not working well, the items in "exception group" are not applied to all levels of the folder tree, it only applied to first one or two levels. I need this "exception group" apply to all sub-folders in the directory tree. How can I fix it?
$RootDir = '\\Data\Production'
$exclude = @('_A', '_B', 'OBSOLETE', 'HOLD')
$result = 'C:\Test\result.txt'
Get-ChildItem $rootdir -Recurse -Directory -Exclude $exclude -Filter 'PML*PROD' |
select-Object fullname |
out-file $result