I am new to Powershell and I am trying to get an understanding of it through borrowing script and making it work for my system. I have a script that I thought would take files from a target folder and zip them into a destination folder. It is creating zip folders in my destination folder based on the names of the files in the target folders, but the zipped folders are empty. How do I get the zipped folders to contain the files from the target folder? I am obviously missing some script or haven't manipulated it enough to work for me. Was hoping to get some expert advice to help aide my journey into Powershell scripting.

Here is the script:

 $Target = "C:\PSTarget"
 $Destination = "C:\PSDest"

 function ZipItUp
$outputFile = [IO.FileInfo] "$Destination\$fldr.zip"
$zipfile = new-object Ionic.Zip.ZipFile

$selfExtractOptions = New-Object Ionic.Zip.SelfExtractorSaveOptions
$selfExtractOptions.Flavor = [Ionic.Zip.SelfExtractorFlavor]::ConsoleApplication
$selfExtractOptions.DefaultExtractDirectory = $outputFile.Directory.FullName
$selfExtractOptions.RemoveUnpackedFilesAfterExecute = $false

$e = $zipfile.AddDirectory("$Target\$fldr")
$zipfile.UseZip64WhenSaving = [Ionic.Zip.Zip64Option]::Always

$zipfile.SaveSelfExtractor($outputFile.FullName, $selfExtractOptions)


foreach ($fldr in Get-ChildItem $Target)
Write-Host "Zipping up $fldr to PSDest"

Thanks in advance,


4 Years
Discussion Span
Last Post by stevo7624
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.