How does the Get-ChildItem -Exclude parameter work? What are the rules followed?
Get-Help for Get-ChildItem is not detailed:
Omit the specified elements. The value of this parameter qualifies the path parameter. Enter an element or path template, for example "* .txt". Wildcards are allowed.
And on Stackoverflow and elsewhere, the general consensus seems too complicated to use, and we all just need to output Get-ChildItem output to Where-Object.
While I'm ready to use the Where-Object, I'm curious about the -Exclude rules.
For example, I have a folder with the following subfolders:
HsacFixtures HsacFixturesBuild RestFixture RestFixtureBuild
If I run the following command:
Get-ChildItem $rootFolderPath -Exclude HsacFixturesBuild -Directory
it returns the expected results:
HsacFixtures RestFixture RestFixtureBuild
However, if I add the -Recurse parameter:
Get-ChildItem $rootFolderPath -Exclude HsacFixturesBuild -Directory -Recurse
It then returns the subfolders in the HsacFixturesBuild folder.
I also tried HsacFixturesBuild\ and HsacFixturesBuild\* , which have the same results.
So, -Exclude applies only to immediate children, not grand-children or deeper subfolders?