2

我在文件夹中有与 M*,S* 匹配的文件:

PS E:\Uploader> dir M*,S*
    Directory: E:\Uploader
Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-----         6/05/2013  10:43 AM    5046659 M_1813O.zip
-a---        26/04/2013   4:51 PM        233 SurveyUploader.config
-a---         8/05/2013   5:15 PM      11788 SurveyUploader.log
-a---         8/05/2013   5:15 PM       6078 SurveyUploader.ps1
-----         6/05/2013  10:43 AM    3473113 S_1813O.zip

我只是想将此过滤器传递给变量中的 gci,但它不起作用:

PS E:\Uploader> $k="M*,S*"
PS E:\Uploader> gci *.* -include $k | where {!$_.PsIsContainer}
PS E:\Uploader> gci *.* -include @($k) | where {!$_.PsIsContainer}
<<no files returned!>>

如果我不将过滤器保存在变量中,它可以正常工作:

PS E:\Uploader> gci *.* -include S*,M* | where {!$_.PsIsContainer}
    Directory: E:\temp\SurveyLoadingAutomation\Uploader
Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-----         6/05/2013  10:43 AM    5046659 M_1813O.zip
-a---        26/04/2013   4:51 PM        233 SurveyUploader.config
-a---         8/05/2013   5:15 PM      11788 SurveyUploader.log
-a---         8/05/2013   5:15 PM       6078 SurveyUploader.ps1
-----         6/05/2013  10:43 AM    3473113 S_1813O.zip

但我需要在脚本的变量中传递过滤器。

任何想法?

4

1 回答 1

5

试试这样:

$k=  @("M*","S*")

-include参数接受(类型的[string[]]数组string

于 2013-05-08T07:33:48.440 回答