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,


Nevermind. Have it all figured out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.