11

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.

manukranthk
  • 119
  • 1
  • 4

3 Answers3

11

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
EM0
  • 5,369
  • 7
  • 51
  • 85
7

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.

mjolinor
  • 66,130
  • 7
  • 114
  • 135
  • Thanks for your reply. The page has many more default parameters that one using winrm has to checkout. – manukranthk Mar 14 '12 at 07:08
  • Using remote/background jobs means you're going to be dealing with constrained runspaces and deserialized objects being returned. What works in a local/unconstrained runspace may need to be re-factored to work in that enviroment. – mjolinor Mar 14 '12 at 10:49
0

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

Sasquatch
  • 49
  • 1
  • 4