powershell add file to zip

Question:

I’m trying to add a file to a zip file using powershell

I can create the zip file but can’t work out how to add my file to it

I’m using

This create the zip file but doesn’t add the new file

I tried the following code I found on stackoverflow which works

but that add a file created by powershell whereas I want to add an existing file

Any help would be much appreciated

Answer:

The CopyHere function just takes a string that is the path to your file. For example:

Edit: The Powershell Pack mentioned in the tip below is no longer available. I leave it here in case someone can find it archived somewhere and can update this post with a link.

Tip:

The Powershell Pack Module has some useful tools, one of which is a zip utility, which will reduce your code to 1 line:

Source:

powershell add file to zip by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply