I'm able to recursively search a directory using Get-ChildItem -Recurse to locate a particular directory, but I'm only interested in the case where the directory is a child of another specific directory. The parent/child may exist at any arbitrary depth in the directory tree. For instance:
C:\lev1\lev2\lev3\lev4\parentDir\childDirToFind\lev7...
The following code returns all occurrences of childDirToFind :
Get-ChildItem -Path C:\\*\\*\ChildDirToFind -Recurse
I've tried including the parentDir in the -Path option and get no results; e.g.:
Get-ChildItem -Path C:\\*\\*\parentDir\childDirToFind -Recurse
I've also tried to use the -Filter option with no results. Perhaps Get-ChildItem isn't the best approach? Ideally, I'd like Get-ChildItem to return immediately after finding the directory and not continue searching the entire tree.
Get-ChildItem -Path c:\ -Recurse -Filter childDirToFind
– Kory Gillgci x:\start -dir -rec -filter childDirToFind |? {$_.Parent.Name -eq 'parentDir'} | select -first 1
– user6811411\lev7..
isn't possible. – user6811411