I am using Windows Server 2012 R2 (64 bit). I have powershell version 4 available in it. I am trying to zip and unzip files. When I try Write-Zip command, it throws me following
Write-Zip
seems to be part of http://pscx.codeplex.com/ that require a separate installation before you can use it.
However, if you just want to create a Zip archive from a folder, you could just run
$source = "c:\temp\source"
$archive = "c:\temp\archive.zip"
Add-Type -assembly "system.io.compression.filesystem"
[io.compression.zipfile]::CreateFromDirectory($source, $archive)
This utilizes the CreateFromDirectory
method from the .NET Framework class ZipFile
. It creates a zip archive from the files located inside the $source
folder and creates an archive as defined in the $archive
variable. Note, ZipFile class was introduced in .NET Framework 4.5