【问题标题】:Compress-Archive command returns "Exception: Stream was too long."Compress-Archive 命令返回“异常:流太长”。
【发布时间】:2017-01-27 10:10:56
【问题描述】:

我这里有一个简单的脚本来存档以“存档”名称开头的日志,然后删除这些文件,只留下存档。

cd L:\

$Source =  Get-ChildItem L:\ | Where{$_.Name -match "^Archive.*\.evtx$"} |Get-ChildItem -name

$CurrentDate = get-date -Format M.d.yyyy

$Destination = "$CurrentDate.zip"

Compress-Archive -Path $Source -destinationpath $Destination

rm L:\$Source

但是,当脚本运行时,我收到以下错误:

使用“3”个参数调用“Write”的异常:“流太长。”在 C:\windows\system32\windowspowershell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:809 字符:29
+ ... $destStream.Write($buffer, 0, $numberOfBytesRead)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : IOException

有什么建议吗?

【问题讨论】:

  • 数据是否超过 4GB 或 65,555 个文件?
  • 大于 4 GB。我假设这会像执行“发送到 > 压缩(压缩)文件夹”时一样工作
  • 我相信 Windows 资源管理器可能使用 Zip64 而不是 Zip。原始 zip 是 32 位的,因此有大小限制。我相信有一些模块或方法可以使用 dotNet 来利用 Zip64。但更好的答案可能是使用 7zip,因为档案也可以更好地压缩。 PSGallery 上有 7Zip4Powershell 模块可能是更好的选择
  • 谢谢本!我将日志大小从 5 GB 减少到 4 GB。 7zip4powershell 不接受我的 $source 作为源参数。我需要稍微更改原始脚本才能使其正常工作。此问题与使用 compress-archive 命令的 32 位 zip 有关。 7zip4powershell 可能是一个替代解决方案。再次感谢!

标签: powershell compression


【解决方案1】:

Compress-Archive 依赖于 Microsoft .NET Framework API System.IO.Compression.ZipArchive 来压缩文件,目前您可以使用 Compress-Archive 压缩的最大文件大小为 2 GB。这是底层 API 的限制。

更多信息请访问:here

【讨论】:

    猜你喜欢
    • 2019-08-27
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-26
    • 2015-11-12
    • 1970-01-01
    相关资源
    最近更新 更多