July 4, 2025

USEFUL-IT

A blog for USEFUL-IT information

Add Files to ZIP

Add files to a zipfile using powershell.

This script is creating a zip file from files in a specific folder.

See also the other scripts I created.

Usage : dir c:\demo\files*.* -Recurse | Copy-Zip c:\demo\myzip.zip

 

 

 

Other Scripts in this range
New-zip Get-zip Extract-Zip Move-Zip Copy-Zip

 

 

 

 


 

 

 

 

############################################################
#
#    NAME : ADD-ZIP
#
#    AUTHOR : Wessel van Sandwijk
#
#    Website : http://www.useful-it.nl
#
#    COMMENT : Add files to ZipFile
#
#    VERSION HISTORY :
#    1.0  07-MRT-2013  -  Initial Version
#
############################################################

dir c:\demo\files\*.* -Recurse | Add-Zip c:\demo\myzip.zip

############################################################
#
#    FUNCTIONS
#
############################################################
function Add-Zip
{
param([string]$zipfilename)
if(-not (test-path($zipfilename)))
{
set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
(dir $zipfilename).IsReadOnly = $false
}
$shellApplication = new-object -com shell.application
$zipPackage = $shellApplication.NameSpace($zipfilename)
foreach($file in $input)
{
$zipPackage.CopyHere($file.FullName)
Start-sleep -milliseconds 500
}
}

About The Author