Powershell – Compress-Archive command returns “Exception: Stream was too long.”

compressionpowershell

I have a simple script here to archive logs that begin with the name "Archive" then delete those files leaving only the 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

However, I receive the below error when the script runs:

Exception calling "Write" with "3" argument(s): "Stream was too long." At
C:\windows\system32\windowspowershell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:809
char:29
+ … $destStream.Write($buffer, 0, $numberOfBytesRead)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : IOException

Any suggestions?

Best Answer

Compress-Archive relies upon the Microsoft .NET Framework API System.IO.Compression.ZipArchive to compress files, the maximum file size that you can compress by using Compress-Archive is currently 2 GB. This is a limitation of the underlying API.

Please see more at : here

Related Topic