5
votes

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?

1
Is data over 4GB or 65,555 files?BenH
It is larger than 4 GB. I'd assume this would work as it does when doing "Send to > Compressed (Zipped) folder"selachka
I believe Windows Explorer may use Zip64 rather than Zip. The original zip was 32 bit, hence the size limitation. I believe that there are some modules or a way to use dotNet to utilize Zip64. But the better answer may be to use 7zip as the archives would also be compressed better. There is the 7Zip4Powershell module on the PSGallery that may be the better alternativeBenH
Thanks Ben! I reduced my log sizes from 5 GB to 4GB. 7zip4powershell did not accept my $source as a source parameter. I would need to change the original script a bit for it to work. This issue was related to the 32bit zip that was used with compress-archive command. 7zip4powershell could be an alternate solution. Thanks again!selachka

1 Answers

5
votes

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