Powershell – How to complete/close a zip file in powershell


I want to create a zip file in powershell, add items to the zip file, then get the compressed content of that zip file as bytes immediately after the zip file is created, in the same scipt. The problem is that it does not seem that the zip application has written its contents to the file system. How does one close/flush the zip application so that the next powershell statement can gain access to the newly created zip file?


The “dir test.zip” shows a zip file with no contents, thus the Get-Content returns nothing.

Please note that this seems to be a problem with the asynchronous behavior of the copyhere action. If I sleep after the copyhere line, the zip file will become populated. However, I do not know how long one must sleep, nor do I want to delay the processing.

Much Thanks in advance!


This method to zip files is not appropriate for automated scripts. This has limitations in Windows 2003 and Windows xp server for 3 gigs. Also, it does not give proper errors.


Powershell – How to complete/close a zip file in powershell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply