I need to compress a folder with power shell.
There is my code:
Get-ChildItem $YourDirToCompress -Directory |
where { $_.Name -notin $DirToExclude} |
Compress-Archive -DestinationPath $ZipFileResult -Update
Move-Item -Path $ZipFileResult -Destination $ZipFileDest
I get:
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:820
char:29
+ ... $destStream.Write($buffer, 0, $numberOfBytesRead)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : OutOfMemoryException
I have set :
Set-Item WSMan:\localhost\Plugin\Microsoft.PowerShell\Quotas\MaxMemoryPerShellMB 8000
Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 8000
Restart-Service WinRM
The whole file is about 1.9 GiB and the compressed file is 500 MiB. I find it hard to believe it is really a memory problem.
Also, once or twice it succeeded on file creation (when MaxMemoryPerShellMB was set to 4000). But most times it fails.
What can I do?