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!

3

1 Answer 1

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)
}
Sign up to request clarification or add additional context in comments.

1 Comment

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."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.