我在文件夹中有与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
但我需要在脚本中的变量中传递过滤器。
有什么想法吗?
答案 0 :(得分:5)
试试这样:
$k= @("M*","S*")
-include
参数接受[string[]]
(string
类型的数组)