OutOfMemory Exception on remote execution using Powershell Invoke-Command

删除回忆录丶 提交于 2019-12-04 00:32:24

问题


I am trying to execute an exe on a remote computer using invoke-command. Executing the exe on the remote machine after logging into the machine using remote desktop takes 1GB of memory and executes to completion after a minute. Whereas when I execute the same exe using Invoke-Command on the same machine, the process returns an OutOfMemoryException and ends suddenly. My invoke command is as simple as Invoke-Command -Session $someSessionVariable -ScriptBlock {Invoke-Expression "abc.exe --arg arg"} -AsJob.

Am I missing something regarding the restrictions on remote invocation?

Thanks in Advance.


回答1:


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 1000000
Set-Item WSMan:\localhost\Plugin\Microsoft.PowerShell\Quotas\MaxMemoryPerShellMB 1000000
Restart-Service WinRM



回答2:


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.




回答3:


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

sl WSMan:\localhost\Shell
Set-Item MaxMemoryPerShellMB 300

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



来源:https://stackoverflow.com/questions/9665981/outofmemory-exception-on-remote-execution-using-powershell-invoke-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!