简体   繁体   中英

Zip individual files in powershell version 3

we have windows 2012 servers and we have powershell version 3. I'm trying to zip log files individually in a folder based on date condition. Compress-Archive is not available in version 3. we do not have any 3rd party zip utilities like WinZip, 7z..etc I tried using [System.IO.Compression.ZipFile] class but it has no flexibility to zip individual files.

My requirement is, to capture the log files based on date and send them through loop to zip each file and delete original file. Your help in this regard is much appreciated.

Thanks in advance.

This answer works fine - it's using COM rather than pure .NET methods:

https://serverfault.com/a/456496/204875

Although, to be honest, I highly recommend downloading the portable version of 7zip and using that. No installation required, a lot more efficient and faster. If you can distribute a script, you can usually distribute an exe with it (although, yes, some environments are highly regulated).

This solution has been thoroughly tested on Windows Server 2012 and doesn't require the shell COM object. Consequently it can run unattended. I have scheduled it to run daily via Windows Task Scheduler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM