1

I'm extracting a ZIP file in PowerShell by using the DotNetZip library, and I want to display progress. I'm using the following code:

try {
    $zip = [Ionic.Zip.ZipFile]::Read($ZipFileName)

    Register-ObjectEvent `
            -InputObject $zip `
            -EventName ExtractProgress `
            -SourceIdentifier ExtractProgress `
            -Action {
                [Console]::Beep()
                Write-Host $Sender
                Write-Host $SourceEventArgs
            } | Out-Null

    $zip.ExtractAll($Destination, 'OverwriteSilently')
}
finally {
    Unregister-Event -SourceIdentifier ExtractProgress
    $zip.Dispose()
}

My problem is that I don't see the events (no beep, no Write-Host) until the very end. I'm expecting to see progress events during the process.

Initially, I thought it was because Register-ObjectEvent queued the events, but the PowerShell help says that -Action is invoked immediately, without the event being queued.

If I write the equivalent code in a C# console application, then I see the progress events as each file is extracted, as expected, which means that (as far as I can tell) DotNetZip is doing the right thing. Note that the events are raised on the same thread that called ExtractAll.

What am I doing wrong?

(Windows 7 x64, PowerShell 2.0, configured to use .NET 4.0)

Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380
  • On windows 7 x32 and powershell 3.0 works. I can see the $sender string and hear the beep multiple times till finished extraction. (ioniczip is 1.8.1.9 ) – CB. Feb 12 '13 at 16:55
  • If I try this, I get multiple beeps, and the output written as expected, but it doesn't happen until right at the very end -- after all of the files are extracted. I can confirm this by hooking the `Extracting_BeforeExtractFile` event type -- the file that's "about" to be extracted already exists. – Roger Lipscombe Feb 14 '13 at 10:13

0 Answers0