Is it possible to create a zip archive using PowerShell?
Thank you.
Is it possible to create a zip archive using PowerShell?
Thank you.
Not out of the box but you can use SharpZipLib with PowerShell
If you head on over to CodePlex and grab the PowerShell Community Extensions, you can use their write-zip
cmdlet.
This is really obscure but works. 7za.exe is standalone version of 7zip and is available with install package.
# get files to be send
$logFiles = Get-ChildItem C:\Logging\*.* -Include *.log | where {$_.Name -match $yesterday}
foreach ($logFile in $logFiles)
{
Write-Host ("Processing " + $logFile.FullName)
# compress file
& ./7za.exe a -mmt=off ($logFile.FullName + ".7z") $logFile.FullName
}
For compression, I would use a standard library (7-zip is good like Michal
suggests).
If you install 7-zip, the installed directory will contain 7z.exe which is a console application.
You can invoke it directly and use any compression option you want.
If you wish to engage with the DLL, that should also be possible.
7-zip is freeware and open source.
What about System.IO.Packaging.ZipPackage? Requires .NET framework version >= 3.0.