Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法传递Powershell参数以从Get ChildItem中排除参数_Powershell - Fatal编程技术网

无法传递Powershell参数以从Get ChildItem中排除参数

无法传递Powershell参数以从Get ChildItem中排除参数,powershell,Powershell,我发现powershell已从压缩存档cmdlet;但是,如果我将powershell参数传递到-exclude参数中,它将不起作用。如果它从powershell变量调用,则它正在工作。我错过什么了吗?请告知 此脚本不起作用。下面是powershell参数 .\createzipfile.ps1“C:\temp”C:\Myzipdir“myzipfile.zip ““web.config”、“PageBase.master”” 此脚本正在工作,但我确实需要-exclude从powershell参

我发现powershell已从压缩存档cmdlet;但是,如果我将powershell参数传递到-exclude参数中,它将不起作用。如果它从powershell变量调用,则它正在工作。我错过什么了吗?请告知

此脚本不起作用。下面是powershell参数

.\createzipfile.ps1“C:\temp”C:\Myzipdir“myzipfile.zip ““web.config”、“PageBase.master””

此脚本正在工作,但我确实需要-exclude从powershell参数传递

.\createzipfile.ps1“C:\temp”C:\Myzipdir“myzipfile.zip

致以最良好的祝愿,
安迪·范(Andy Pham)

目前我无法100%测试这一点,但我愿意这样做,这将为您排忧解难

在第一个示例中,排除的参数是:
[string]$excludefilepattern

这将接受一个字符串,您要传递的是一个看起来像数组的字符串。我假设这是因为您在尝试传入真实数组时出错

修复方法是将该参数表示为能够接受字符串数组:

[string[]]$excludefilepattern
然后,当您提供一个数组时,它就会工作(注意,我已经删除了外部单引号):


这方面的帮助是检查您正在使用的cmdlet的帮助页面。在本例中,您将注意到exclude列为
[-exclude]
。方括号让您知道它需要一个任何类型的数组(本例中为字符串)。

目前我无法100%测试它,但我愿意这样做,这将为您排序

在第一个示例中,排除的参数是:
[string]$excludefilepattern

这将接受一个字符串,您要传递的是一个看起来像数组的字符串。我假设这是因为您在尝试传入真实数组时出错

修复方法是将该参数表示为能够接受字符串数组:

[string[]]$excludefilepattern
然后,当您提供一个数组时,它就会工作(注意,我已经删除了外部单引号):


这方面的帮助是检查您正在使用的cmdlet的帮助页面。在本例中,您将注意到exclude列为
[-exclude]
。方括号让您知道它想要一个任何类型的数组(本例中为字符串)。

既然您没有提到每个参数的位置,最好使用它命名。当您这样做时,传递的多个文件模式将不会有任何歧义。当然,不要把这些模式放在一个引号里。比如:

\createzipfile.ps1-源“C:\temp”-目标“C:\Myzipdir”-Zipfilename myzipfile.zip-排除文件模式“web.config”,“PageBase.master”


此外,文件模式不能是字符串。因为要传递多个,所以它必须是一个数组。最好不要在param块内键入caste$ExcludeFilePattern

,因为您没有提到每个参数的位置,最好使用它命名。当您这样做时,传递的多个文件模式将不会有任何歧义。当然,不要把这些模式放在一个引号里。比如:

\createzipfile.ps1-源“C:\temp”-目标“C:\Myzipdir”-Zipfilename myzipfile.zip-排除文件模式“web.config”,“PageBase.master”


此外,文件模式不能是字符串。因为要传递多个,所以它必须是一个数组。最好不要在param块中键入caste$ExcludeFilePattern

不要引用最后一个参数
“web.config”,“PageBase.master”
应该是
“web.config”,“PageBase.master”
不要引用最后一个参数
“web.config”,“PageBase.master”
应该是
“web.config”,“PageBase.master”
是,-从cmdlet Get-ChildItem数组中排除参数。我的脚本按预期工作。愚蠢的错误-:)。非常感谢WindosYes,cmdlet Get-ChildItem中的-exclude参数为数组。我的脚本按预期工作。愚蠢的错误-:)。非常感谢Windos
[string[]]$excludefilepattern
.\createzipfile.ps1 "C:\temp" "C:\Myzipdir" myzipfile.zip "web.config","PageBase.master"