简体   繁体   English

Zip powershell 版本 3 中的单个文件

[英]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.我们有 windows 2012 服务器,我们有 powershell 版本 3。我正在尝试根据日期条件将 zip 日志文件单独放在一个文件夹中。 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. 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.我的要求是,根据日期捕获日志文件并通过循环将它们发送到 zip 每个文件并删除原始文件。 Your help in this regard is much appreciated.非常感谢您在这方面的帮助。

Thanks in advance.提前致谢。

This answer works fine - it's using COM rather than pure .NET methods:这个答案工作正常 - 它使用 COM 而不是纯 .NET 方法:

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

Although, to be honest, I highly recommend downloading the portable version of 7zip and using that.虽然,老实说,我强烈建议下载 7zip 的便携版本并使用它。 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).如果您可以分发脚本,通常可以使用它分发 exe(虽然,是的,某些环境受到严格监管)。

This solution has been thoroughly tested on Windows Server 2012 and doesn't require the shell COM object. 此解决方案已在 Windows Server 2012 上进行了全面测试,不需要 shell COM ZA8CFFDE6931BD4B666AC9。 Consequently it can run unattended.因此它可以在无人看管的情况下运行。 I have scheduled it to run daily via Windows Task Scheduler.我已通过 Windows 任务计划程序安排它每天运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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