Get-ChildItem -Filter Array

Situation:

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

  • It works:

     $Path = "$env:windir\system32\*" $GuyArray = @("*.dll", "*.exe") Get-ChildItem $Path -Include $GuyArray 
  • But I can't get this to work:

     $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 the 'Filter' parameter. The specified method is not supported.

Questions:

  • Does this mean that -Include supports multiple values, but -Filter allows only one value?
  • If the above explanation is correct, is there a way I could detect this from Get-Help gci ?
+4
source share
3 answers

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

Yes.

If the above explanation is correct, is there a way I could discover from Get-Help gci ?

Yes, but you do not get much information from Get-Help gci -Parameter Filter . But you can still see that it is a string, not an array. In terms of parts, Filter is a vendor- Filter filter. Get-Help gci cannot say anything about the implementation in a particular provider. Theoretically, the Get-Help FileSystem (help about this provider) should have explained this.

PS Also note that this filter uses CMD template rules rather than wilcard PowerShell rules.

+3
source

Using Get-Help :

 > get-help Get-ChildItem NAME Get-ChildItem SYNTAX Get-ChildItem [[-Path] <string[]>] [[-Filter] <string>] [-Exclude <string[]>] [-Force] [-Include <string[]>] [-Name] [-Recurse] [-UseTransaction] [<CommonParameters>] 

The SYNTAX section includes parameter types from which you can see that Filter is a string and Path is an array.

+1
source

Question 1:

Yes. -Filter accepts only [string] as input. -Include accepts [String[]] .

Question 2:

Get-help get-childitem -parameter filter gives

 -Filter <string> ...explanation... 

Get-help get-childitem -parameter include gives

 -Include <string[]> ...explanation... 
+1
source

Source: https://habr.com/ru/post/1439376/


All Articles