Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OutOfMemory Exception on remote execution using Powershell Invoke-Command

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.

like image 304
manukranthk Avatar asked Mar 12 '12 11:03

manukranthk


2 Answers

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
like image 63
EM0 Avatar answered Nov 13 '22 11:11

EM0


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.

like image 26
mjolinor Avatar answered Nov 13 '22 10:11

mjolinor