OutOfMemory Exception on remote execution using Powershell Invoke-Command OutOfMemory Exception on remote execution using Powershell Invoke-Command powershell powershell

OutOfMemory Exception on remote execution using Powershell Invoke-Command


Complete PowerShell script, based on mjolinor's answer, for anyone who wants to skip the reasons and just make it work:

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


From:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa384372(v=vs.85).aspx

The defult memory limit on remote shells is 150MB

MaxMemoryPerShellMB Specifies the maximum amount of memory allocated per shell, including the shell's child processes. The default is 150 MB.


As an addition to mjolinor's answer, you can change the MaxMemoryPerShellMB by running:

sl WSMan:\localhost\ShellSet-Item MaxMemoryPerShellMB 300

Ref: http://blogs.technet.com/b/heyscriptingguy/archive/2013/07/30/learn-how-to-configure-powershell-memory.aspx