1

I want to zip a file using PowerShell v2.0 as I am engineering this code for a legacy server.

On my local machine running PowerShell v5.0 it works fine, but does not on PS v2.

Any idea how to ZIP a file using PS v2?

Compress-Archive -Path $root_folder\temp-file.csv -Update -DestinationPath $root_folder\temp-file.zip

Again, this is for PowerShell v2.0!

Kerbol
  • 588
  • 2
  • 9
  • 24
  • Possible related and duplicates: https://stackoverflow.com/questions/1153126/how-to-create-a-zip-archive-with-powershell, https://stackoverflow.com/questions/40265627/create-a-zip-archive-with-powershell-and-windows-tools, https://stackoverflow.com/questions/11021879/creating-a-zipped-compressed-folder-in-windows-using-powershell-or-the-command-l, and a large number of others – Jeff Zeitlin Jan 30 '19 at 14:51
  • 1
    Possible duplicate of [Creating a zipped/compressed folder in Windows using Powershell or the command line](https://stackoverflow.com/questions/11021879/creating-a-zipped-compressed-folder-in-windows-using-powershell-or-the-command-l) – Jeff Zeitlin Jan 30 '19 at 14:51
  • Possible duplicate of [How to create a zip archive with PowerShell?](https://stackoverflow.com/questions/1153126/how-to-create-a-zip-archive-with-powershell) – marsze Jan 30 '19 at 14:55

1 Answers1

1

Some time ago I have written a function to create a .zip file without the use of Compress-Archive

function createZipFile($outputFileName, $sourceDirectory){
    Add-Type -AssemblyName System.IO.Compression.FileSystem
    $compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
    [System.IO.Compression.ZipFile]::CreateFromDirectory($sourceDirectory, $outputFileName, $compressionLevel, $false)
}
TobyU
  • 3,718
  • 2
  • 21
  • 32
  • Didn't seem to work for me. I got the error "Add-Type : Cannot add type. The assembly 'System.IO.Compression.FileSystem' cou ld not be found." – Kerbol Jan 30 '19 at 15:23