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.

7
  • 3
    blog.patricknielsen.net/2012/01/… Commented Mar 12, 2012 at 11:46
  • Why do you even use iex for calling a native program? PowerShell is a shell. Executing commands is what it does. Commented Mar 12, 2012 at 11:54
  • @Joey - while that is true, powershell has so MANY problems with passing the arguments to an external program that it is at times easier to just use iex Commented Mar 12, 2012 at 16:39
  • But iex ist just a layer above all that problems, at least how I understand it. You just add a layer of indirection while solving no problem at all. Commented Mar 12, 2012 at 18:49
  • Thanks David, the suggestion helped. Commented Mar 14, 2012 at 7:07

3 Answers 3

12

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
Sign up to request clarification or add additional context in comments.

Comments

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.

2 Comments

Thanks for your reply. The page has many more default parameters that one using winrm has to checkout.
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.
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.