问题
I'm trying to copy files into a zip file. I used start-job and wait-job to wait for the copy process finish but it didnt work at all. This is the error when I call 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
This is my code
$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
}
Any idea?
Update
@PetSerAI, I also try to put that COM object into the job but it doesnt work too. Receive-job doesn't show anything. Below is the new code:
$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
来源:https://stackoverflow.com/questions/34237490/start-job-wait-job-doesnt-work-with-copy-here