Powershell 启动作业等待作业不执行';Don’我不能用copy.here

Powershell 启动作业等待作业不执行';Don’我不能用copy.here,powershell,comobject,Powershell,Comobject,我正在尝试将文件复制到zip文件中。我使用start job和wait job来等待复制过程完成,但它根本不起作用。 这是调用receive job时出现的错误: Method invocation failed because [Deserialized.System.__ComObject#{a7ae5f64-c4d7-4d7f-9307-4d24ee54b841}] does not contain a method named 'copyhere'. + CategoryIn

我正在尝试将文件复制到zip文件中。我使用start job和wait job来等待复制过程完成,但它根本不起作用。 这是调用receive job时出现的错误:

Method invocation failed because 
[Deserialized.System.__ComObject#{a7ae5f64-c4d7-4d7f-9307-4d24ee54b841}] does not contain a method 
named 'copyhere'.
    + CategoryInfo          : InvalidOperation: (copyhere:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
    + PSComputerName        : local
这是我的密码

$Shell = New-Object -com Shell.Application
$b = $shell.namespace($zippath.ToString())

$files = Get-ChildItem $fileDest -recurse -include *.*
foreach ($file in $files) {
    $job = Start-Job -scriptblock {$args[0].copyhere($args[1].fullname)} -Name copyfiles -argumentlist @($b, $file)
    Wait-Job -name copyfiles
    #Remove-Item -Path $file
}
有什么想法吗

更新

@PetSerAI,我也尝试将COM对象放入作业中,但它也不起作用。接收作业没有显示任何内容。以下是新代码:

$func = {
    $zippath = "d:\nhl\test.zip"
    $Shell = New-Object -com Shell.Application
    $b = $shell.namespace($zippath.ToString())
    $b.CopyHere($args[0].tostring())
    #Remove-Item -Path $filedest
}

$file = "D:\nhl\abc\test.rar"
start-job -ScriptBlock $func -ArgumentList $file

为什么要为每个文件启动作业?请参见此处的第二个答案,也许此方法更适合您:
Start Job
Start new PowerShell进程。请注意类型名称
反序列化.System.\uuu-ComObject{a7ae5f64-c4d7-4d7f-9307-4d24ee54b841}
反序列化
。您无法通过PowerShell的进程边界传递live COM对象,您必须在作业中新建一个。@sodawillow我试过了,但
::CreateFromDirectory
只会将整个目录压缩到新的zipfile中,而我需要将文件添加到现有的zipfile中请参见:您可以使用此方法(问题的最后一个片段)将文件添加到现有的存档中。为什么要为每个文件启动作业?请参见此处的第二个答案,也许此方法更适合您:
Start Job
Start new PowerShell进程。请注意类型名称
反序列化.System.\uuu-ComObject{a7ae5f64-c4d7-4d7f-9307-4d24ee54b841}
反序列化
。您无法通过PowerShell的进程边界传递live COM对象,您必须在作业中新建一个。@sodawillow我尝试过,但是
::CreateFromDirectory
只会将整个目录压缩到新的zipfile中,而我需要将文件添加到现有的zipfile中。请参见:您可以使用此方法将文件添加到现有的存档中(问题的最后一个片段)。