启动作业等待工作不适用于copy.here

时间:2015-12-12 07:34:17

标签: 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'.
    + 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

0 个答案:

没有答案