简体   繁体   English

添加包含参数时,Powershell GCI递归深度停止工作

[英]Powershell GCI Recursive Depth Stops Working When Adding Include Parameter

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. 简而言之,它下载文件名和扩展名的动态列表,导入包含我们每个共享根目录的csv,并比较文件以查找匹配项。

$Directory = Get-ChildItem -Path $path -Recurse -Depth 2 -Include $ExtList -Force

Super simple, right? 超级简单吧? Except the depth parameter isn't working. 除非depth参数不起作用。 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. 唯一的区别是我要删除-Include参数。

$Path is a variable like \\server\\root\\ $ExtList is an array of filenames $ Path是一个类似\\ server \\ root \\的变量$ ExtList是一个文件名数组

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: 做“ Where-Object”我尝试了这个:

$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. 为了进行测试,该脚本大约需要10分钟才能成功运行,并在不到一天的时间内完成。 (715ms to be exact) When I go into debugging, it's like there is nothing being piped into the where-object. (准确地说是715毫秒)当我进入调试程序时,就像没有任何东西通过管道传递到where对象。

在此处输入图片说明

EDIT------ 编辑 - - -

The $ExtList setup looks like this: $ ExtList设置如下所示:

@((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: $ Path从如下所示的csv文件中提取:

在此处输入图片说明

This CSV has over 3000 different shares in it. 此CSV具有3000多种不同的份额。 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. 切换为在Windows Server 2012 R2机器上运行后,depth参数可与include一起使用。 It seems to have been a bug with the version that I was on. 我所使用的版本似乎是一个错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM