1

我正在尝试将文件复制到 zip 文件中。我使用 start-job 和 wait-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 对象放入工作中,但它也不起作用。Receive-job 没有显示任何内容。以下是新代码:

$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
4

0 回答 0