I have what I'm assuming to be a simple question. I have a large block of code that I have written. In short, it downloads a dynamic list of file names and extensions, imports a csv with the roots of every one of our shares, and compares the files to find matches.
$Directory = Get-ChildItem -Path $path -Recurse -Depth 2 -Include $ExtList -Force
Super simple, right? Except the depth parameter isn't working. It recursively searches through every single level. If I do this:
$Directory = Get-ChildItem -Path $path -Depth 2 -Force
The Depth parameter works perfectly and it only searches through the two levels. If I don't include recurse or depth, it works as expected by searching only the top level. The only difference is that I'm removing the -Include parameter.
$Path is a variable like \server\root\ $ExtList is an array of filenames
Again, they both work individually, but not together.
I need to have both the depth and include parameters in here. Does anybody know what I am doing wrong, or if it's a glitch?
Edit ---------------------------
Doing "Where-Object" I tried this:
$Directory = Get-ChildItem -Path $path -Recurse -Depth 2 -Force | Where-Object {$_.Extension -like $ExtList}
And... nothing happens. For testing, this script takes about 10 minutes to successfully run on a good day, it finished in less than 1 second. (715ms to be exact) When I go into debugging, it's like there is nothing being piped into the where-object.
EDIT------
The $ExtList setup looks like this:
@((Invoke-WebRequest -Uri "https://fsrm.experiant.ca/api/v1/get").content | convertfrom-json | % {$_.filters})
That will get you the exact list and format that I'm using.
$Path pulls from a csv file that looks like this:
This CSV has over 3000 different shares in it. I know it's weird, yes I have to do it this way for our infrastructure.
After switching to run on a Windows Server 2012 R2 box, the depth parameter works with include. It seems to have been a bug with the version that I was on.