How can I get 7za.exe to run via Powershell Remoting?
Asked Answered
S

2

12

I've tried a number of different ways to do this, they all result in the same error. Here is one set of commands:

$s = New-PSsession -ComputerName ServerA
$job = Invoke-Command -Session $s -Scriptblock { Start-Process -FilePath    
    "C:\Scripts\ArchiveEventLogs\ver4.5\7za.exe" -ArgumentList "a", 
    "C:\Scripts\Eventlogs.bak\ServerA-20101111.7z", "C:\Scripts\Eventlogs.bak\*.evt*", 
     "-mx7", "-oC:\Scripts\Eventlogs.bak", "-wC:\Scripts\Eventlogs.bak", "-t7z" -Wait }  
     -AsJob

Get-Job | Wait-Job
Receive-Job Job$

The output I get is this:

7-Zip (A) 9.17 beta  Copyright (c) 1999-2010 Igor Pavlov  2010-10-04
Scanning

Creating archive C:\Scripts\Eventlogs.bak\ServerA-20101111.7z

ERROR: Can't allocate required memory!

How can I get past that error???

I should point out, if I run the Scriptblock directly on ServerA without the remoting, it works. Thanks for any help!

Schiffman answered 12/11, 2010 at 22:24 Comment(0)
P
9

Remote shells are limited to 150 MB of memory by default. You can tweak this with the winrm command-line utility on the server; I'm not sure if the powershell wsman:\ drive will let you change this interactively because I think it's a general property of the shell plugin functionality in winrm and not directly connected to powershell.

C:\Windows\system32>winrm get winrm/config/winrs
Winrs
    AllowRemoteShellAccess = true
    IdleTimeout = 180000
    MaxConcurrentUsers = 5
    MaxShellRunTime = 2147483647
    MaxProcessesPerShell = 15
    **MaxMemoryPerShellMB = 150**
    MaxShellsPerUser = 5

Compressing large files is a memory-hungry process.

Penner answered 13/11, 2010 at 1:13 Comment(1)
Thank you very much. I updated my GPO to reflect a higher memory allotment and it worked! In case any one needs it, the GPO location is: Computer Configuration-->Policies-->Admin Templates-->Windows Components--> Windows Remote Shell--> Specify Maximum Memory in MB per Shell. Thanks a ton!Schiffman
H
7

Another solution is to change the configuraiton of the Windows Remote Shell.

You could execute the following in a PowerShell prompt on the remote server:

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

This is especially useful if you don't want to apply the change via Group Policy.

Ps: To see what the currently configured value is try executing the following:

Get-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB
Headley answered 10/5, 2011 at 12:48 Comment(1)
thanks for the alternative, much easier than fiddling with GPOAndrey

© 2022 - 2024 — McMap. All rights reserved.