压缩存档命令返回"Exception: Stream was too long."



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

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

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

异常调用"Write"带"3"参数:"Stream was too long."在C: windows system32系统 Microsoft.PowerShell.Archive Microsoft.PowerShell.Archive.psm1:809 windowspowershell v1.0 模块字符:29日
+……destStream美元。Write($buffer, 0, $numberOfBytesRead)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo: NotSpecified: (:) [], MethodInvocationException
+ fulllyqualifiederrid: IOException

有什么建议吗?

compress - archive依赖于Microsoft . net Framework API System.IO.Compression.ZipArchive来压缩文件,目前使用compress - archive可以压缩的最大文件大小为2gb。这是底层API的一个限制。

详情请见:

我建议使用7z.exe portable。下面是我的示例脚本

$TempFolderName = "I:TempLogs2"
$source = $TempFolderName+'Archive'
$destination = $TempFolderName+'Archive'
$azcopylogs = Get-ChildItem $source -Include *.log -Recurse
foreach ($s in $azcopylogs) {
 
$azcopylogPath = $s.FullName
$azcopylogName = $s.Name
 
C:Tools7Z7z.exe a -t7z  $azcopylogPath'.7z' -r $azcopylogPath
;if (Test-Path $azcopylogPath'.7z') { Remove-Item $azcopylogPath -force }
}

相关内容

最新更新