1

While running below PowerShell command remotely to compress the folder into zip format, getting 'System.OutOfMemoryException'

PS > Compress-Archive -Path \\myserver1\Backup\8159 -DestinationPath \\myserver1\Backup\8159.zip

While running the same command as shown below in myserver1 machine directly then getting Exception calling "Write" with "3" argument(s): "Stream was too long."

PS > Compress-Archive -Path E:\Backup\8159 -DestinationPath E:\Backup\8159.zip

I verified below as well

Get-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB
WSManConfig: Microsoft.WSMan.Management\WSMan::localhost\Shell

Type            Name                           SourceOfValue   Value
----            ----                           -------------   -----
System.String   MaxMemoryPerShellMB                            2147483647
Get-Item WSMan:\localhost\Plugin\Microsoft.PowerShell\Quotas\MaxMemoryPerShellMB
WSManConfig: Microsoft.WSMan.Management\WSMan::localhost\Plugin\microsoft.powershell\Quotas

Type            Name                           SourceOfValue   Value
----            ----                           -------------   -----
System.String   MaxMemoryPerShellMB                            2147483647

Could anyone help me out here?

Thanks in advance...

vahdet
  • 6,357
  • 9
  • 51
  • 106
Piyush
  • 5,145
  • 16
  • 49
  • 71
  • You can find the PowerShell solution using `IO.Compression` [here](https://stackoverflow.com/questions/72607926/how-do-i-compress-files-using-powershell-that-are-over-2-gb) – Santiago Squarzon Oct 19 '22 at 22:21

1 Answers1

3

As stated in the docs, the Compress-Archive cmdlet relies upon the Microsoft .NET API System.IO.Compression.ZipArchive to compress files.

It states that "Therefore, the maximum file size that is 2 GB. This is a limitation of the underlying API."

You will get this error if the data to compress is over that limit.

Perhaps you should better use use 7Zip. You can find a module 7Zip4Powershell in the PSGallery.

Theo
  • 57,719
  • 8
  • 24
  • 41