Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 853
Sean Avatar asked Nov 12 '10 22:11

Sean


People also ask

How do I use PowerShell to remot?

PowerShell remoting is enabled by default on Windows Server platforms. You can use Enable-PSRemoting to enable PowerShell remoting on other supported versions of Windows and to re-enable remoting if it becomes disabled. You have to run this command only one time on each computer that will receive commands.

What is 7za command?

7z a archive. 7z A*. txt -ssc -r compresses all A*. txt files from current directory and all it's subdirectories. That command doesn't compress a*.

What is PowerShell 7 remoting?

This cmdlet will run PowerShell on the local or remote computer and, since it uses a PowerShell session, it has the capability to return all output from that command. This output includes errors, making it incredibly useful to administrators.

What is remoting PowerShell?

Windows PowerShell Remoting. Using the WS-Management protocol, Windows PowerShell remoting lets you run any Windows PowerShell command on one or more remote computers. You can establish persistent connections, start interactive sessions, and run scripts on remote computers.


2 Answers

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.

like image 99
x0n Avatar answered Sep 22 '22 15:09

x0n


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
like image 42
Jaans Avatar answered Sep 22 '22 15:09

Jaans