Please feel free to provide feedback or file bugs here.

Compress-Archive throws "OutOfMemory" on large folders

When using Compress-Archive on a very large folder, I am getting a "OutOfMemory Exception" error. This also happens when I pipe the folder from Get-ChildItem.

PS E:\> Compress-Archive -Path \\servername\downloads\foldername -DestinationPath e:\Foldername_bef
ore-12-01-2016.zip -CompressionLevel Optimal
Exception calling "Write" with "3" argument(s): "Exception of type 'System.OutOfMemoryException' was thrown."
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 : OutOfMemoryException

PS E:\> $Psversiontable

Name Value
---- -----
PSVersion 5.0.10586.117
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.10586.117
CLRVersion 4.0.30319.34209
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

PS E:\>

10 votes
Sign in
(thinking…)
Password icon
Signed in as (Sign out)

We’ll send you updates on this idea

Martin Pugh shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

3 comments

Sign in
(thinking…)
Password icon
Signed in as (Sign out)
Submitting...
  • tekfranz commented  ·   ·  Flag as inappropriate

    But setting Max memory seems a bit unnecessary and people are reporting mixed results.Compress-Archive should have some sort of memory management built-in like other programs like 7Zip. But presently Compress-Archive crashes after consuming all the System Memory.

  • Andy Ray commented  ·   ·  Flag as inappropriate

    So... after a GREAT DEAL of research I ran across the solution. Microsoft PS remote sessions are memory limited to (I think, I didn't check the original value before setting to the new value) 150MB. My compression process usually (when run locally) took about 3GB.

    This StackOverflow post had the solution: http://stackoverflow.com/questions/9665981/outofmemory-exception-on-remote-execution-using-powershell-invoke-command

    They set to 1000 GB... tad excessive... I limited mine to 4GB:

    Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 4000
    Set-Item WSMan:\localhost\Plugin\Microsoft.PowerShell\Quotas\MaxMemoryPerShellMB 4000
    Restart-Service WinRM

  • Andy Ray commented  ·   ·  Flag as inappropriate

    Ran into this exact issue when trying to encompass the Compress-Archive in an Invoke-Command to execute on a remote system. Command operates properly on remote system when executed on the system itself in a PowerShell console.

Feedback and Knowledge Base