Sending remote Extrating events crashes powershell

Nov 23, 2011 at 1:04 PM
Edited Nov 23, 2011 at 1:12 PM

Add-Type -Path 'F:\7zDLLs\SevenZipSharp.dll' #Presumably needed so the main session can grok the 7z events.
[SevenZip.SevenZipExtractor]::SetLibraryPath('F:\7zDLLs\7z64.dll')

Start-Job -InitializationScript { #Needed because sessions don't share modules
  Add-Type -Path 'F:\7zDLLs\SevenZipSharp.dll'
  [SevenZip.SevenZipExtractor]::SetLibraryPath('F:\7zDLLs\7z64.dll')
} -ScriptBlock {
  $extractor = New-Object SevenZip.SevenZipExtractor('D:\prep.7z')
  Register-ObjectEvent -InputObject $extractor -EventName Extracting -Forward
  Write-Host $extractor
  $extractor.ExtractArchive('F:\tmp')
  Write-Host 'Finished!'
}

Without the Register-ObjectEvent this works fine. But it crashes powershell with it. I tried this background job variant as an alternative for simple foreground job plus -Action scriptblock, which doesn't crash, but doesn't generate events except after the extraction is all finished. The whole powershell events stuff is a big M$ snafu.