4

I wrote a powershell script that connects to a remote machine with the intent of executing a software rollout on said machine. Basically it connects, maps a drive, copies the rollout from the mapped drive to the target machine, then executes a perl script to install the rollout. If I do those steps manually everything works fine. When I try using my script, the perl script fails on the remote machine saying, "The paging file is too small for this operation to complete".

Can someone explain the considerations I need to take into account when operating remotely? I've tried monitoring memory usage and I don't see anything out of the ordinary. Is the page file OS wide or is there some type of per user configuration my script should be setting when it connects?

I can post snippets of my script if needed, but the script is 426 lines so I think it would be overwhelming to post in its entirety.

JDH
  • 2,618
  • 5
  • 38
  • 48

2 Answers2

7

I found that the remote shells are managed differently than logging onto the box and executing a powershell session. I had to increase the maximum amount of memory available using one of the commands below:

Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1024

winrm set winrm/config @{MaxMemoryPerShellMB="1024"}

The default is 150MB which didn't cut it in my case. I can't say that I recommend 1GB, I'm just a developer. I tried upping it until I found what worked for me.

JDH
  • 2,618
  • 5
  • 38
  • 48
  • Is it possible to configure this remotely? – Maverick Jan 14 '13 at 15:29
  • Assuming proper permissions you should be able to do: Invoke-Command -ComputerName YOUR_COMPUTER_NAME { Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1024 } – JDH Jan 17 '13 at 14:49
  • There is no UAC enabled and the user has permissions to run commands with elevated privileges. Still doesn't work. Guess i have to create my own C# utility because even when it works i can't capture the output. – Maverick Jan 17 '13 at 17:15
  • I know I had to issue the "Set-ExecutionPolicy unrestricted" command locally on on all machines prior to remotely executing scripts, maybe that is the missing piece? What error is it giving when you try to run your command? – JDH Jan 17 '13 at 18:42
  • I tried the following code but still get errors when installing the net framework remotely. – Maverick Jan 17 '13 at 20:42
  • I had to use winrm/config/winrs instead of winrm/config on server 2008 – uNople Jan 22 '15 at 23:10
0

I tried this code to run the puppet client as an administrator but the framework still complains with "Access Denied"

Exe (C:\Users\lmo0\AppData\Local\Temp\Microsoft .NET Framework 4 Setup_4.0.30319\Windows6.1-KB958488-v6001-x64.msu) failed with 0x5 - Access is denied. .

using System;
using System.Diagnostics;

namespace RunAsAdmin
{
    class Program
    {
        static void Main(string[] args)
        {
            Process proc = new Process();

            Process p = new Process();
            p.StartInfo.FileName = @"powershell.exe";
            p.StartInfo.Arguments = @"invoke-command -computername vavt-pmo-sbx24 -ScriptBlock {&'C:\Program Files (x86)\Puppet Labs\Puppet\bin\puppet.bat' agent --test --no-daemonize --verbose --logdest console}";
            p.StartInfo.Verb = "runas";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

            p.Start();

            while (p.HasExited == false) {
               Console.WriteLine(p.StandardOutput.ReadLine());
            }
            Console.ReadLine();
            p.WaitForExit();
            p.Close();


        }
    }
}
Maverick
  • 1,293
  • 1
  • 19
  • 39
  • Can you run the powershell command outside of the .net code? You're going to want to post this as a separate question. The other stack users won't see this because it was posted as an answer to a post that already has an accepted answer. – JDH Jan 17 '13 at 21:13
  • There is no wat to add code on the comments and that is the reason why i posted on the answer. Any other way of posting code? – Maverick Jan 17 '13 at 21:19
  • Code can't be placed in the comments. If you post this as its own question you'll be able to post the code. Then others will see it as well which will benefit you. – JDH Jan 17 '13 at 21:40