我正在尝试将多个参数传递给我的scriptblock:
$ConfigFile = @("C:\zip1.zip","C:\zip2.zip")
$unzippath = "C:\"
$ScriptBlock = {
param($ConfigFile,$unzippath)
$shell = new-object -com shell.application
$zip = $shell.NameSpace($ConfigFile)
foreach($item in $zip.items())
{
$shell.Namespace($unzippath).copyhere($item)
}
}
Start-Job -Scriptblock $ScriptBlock -ArgumentList $ConfigFile,$unzippath
但它失败了。有人能帮助我吗?
答案 0 :(得分:0)
您做得对,$ConfigFile
作为array
传递。所以你的问题是而不是将参数传递给scriptblock
。它更像是如何使用Shell.application
提取多个zip文件。
您可能必须使用Foreach-Object cmdlet迭代每个zip并提取它:
$ConfigFile = @("C:\zip1.zip","C:\zip2.zip")
$unzippath = "C:\"
$ScriptBlock = {
param($ConfigFile,$unzippath)
$ConfigFile | ForEach-Object {
$shell = new-object -com shell.application
$zip = $shell.NameSpace($_)
foreach($item in $zip.items())
{
$shell.Namespace($unzippath).copyhere($item)
}
}
}
Start-Job -Scriptblock $ScriptBlock -ArgumentList $ConfigFile,$unzippath