Get-ChildItem -Filter数组 [英] Get-ChildItem -Filter Array

查看:168
本文介绍了Get-ChildItem -Filter数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况:
$ b $ ol
Get-ChildItem $ Path -Filter * .dll

  
  • > $ Path =$ env:windir \system32\ *
    $ GuyArray = @(* .dll,* .exe)

    Get-ChildItem $ Path - 包括$ GuyArray


  • 但是我无法得到这个工作:

      $ Path =$ env:windir \system32\ *
    $ GuyArray = @(*。dll,*。 )

    Get-ChildItem $ Path -Filter $ GuyArray




  • $ p
    $ b


    无法将'System.Object []'转换为'System .String'参数'Filter'需要。不支持指定的方法。


    问题:


    1. 这是否意味着 -Include 支持多个值,但是 -Filter 只允许一个值?

    2. 如果上面的解释是正确的,有没有一种方法可以从 Get-Help gci
    3. 中找到

      解决方案


      这是否意味着 -Include 支持多个值,但是 -Filter 只允许一个值?

      是的。
      $ b


      如果上面的解释是正确的,有没有一种方法可以从 Get-Help gci


      是的,但是您没有通过 Get-帮助gci -Parameter Filter 。但你仍然可以看到它是一个字符串,而不是一个数组。至于细节, Filter 是一个提供程序特定的过滤器。 Get-Help gci 不能告诉你任何有关在特定提供程序中实现的信息。从理论上讲, Get-Help FileSystem (关于这个提供者的帮助)应该已经解释了这一点。

      另外请注意,这个过滤器比PowerShell wilcard规则更使用CMD通配符规则。


      Situation:

      1. Get-ChildItem $Path -Filter *.dll works for me

      2. This works:

        $Path = "$env:windir\system32\*"
        $GuyArray = @("*.dll", "*.exe")
        
        Get-ChildItem $Path -Include $GuyArray
        

      3. But I cannot get this working:

        $Path = "$env:windir\system32\*"
        $GuyArray = @("*.dll", "*.exe")
        
        Get-ChildItem $Path -Filter $GuyArray
        

      Error message:

      Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Filter'. Specified method is not supported.

      Questions:

      1. Does this mean that -Include supports multiple values, but -Filter only allows one value?
      2. If the above explaination is correct, is there a way I could have discovered this from Get-Help gci?

      解决方案

      Does this mean that -Include supports multiple values, but -Filter only allows one value?

      Yes.

      If the above explaination is correct, is there a way I could have discovered this from Get-Help gci?

      Yes, but you do not get much information by Get-Help gci -Parameter Filter. But you still can see it is a string, not an array. As for the details, Filter is a provider-specific filter. Get-Help gci cannot tell you anything about implementation in a particular provider. In theory, Get-Help FileSystem (help about this provider) should have explained this.

      P.S. Also note that this filter rather uses CMD wildcard rules than PowerShell wilcard rules.

      这篇关于Get-ChildItem -Filter数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆