如何通过 Powershell Remoting 运行 7za.exe?

发布于 2024-10-01 22:02:38 字数 810 浏览 10 评论 0原文

我尝试了多种不同的方法来执行此操作,它们都会导致相同的错误。 这是一组命令:

$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$

我得到的输出是这样的:

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!

我怎样才能克服这个错误???

我应该指出,如果我直接在 ServerA 上运行 Scriptblock 而无需远程处理,它就可以工作。 感谢您的帮助!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神经大条 2024-10-08 22:02:38

默认情况下,远程 shell 的内存限制为 150 MB。您可以使用服务器上的 winrm 命令行实用程序对此进行调整;我不确定 powershell wsman:\ 驱动器是否会让您以交互方式更改此设置,因为我认为这是 winrm 中 shell 插件功能的一般属性,而不是直接连接到 powershell。

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

压缩大文件是一个非常消耗内存的过程。

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.

仅此而已 2024-10-08 22:02:38

另一个解决方案是更改 Windows 远程 Shell 的配置。

您可以在远程服务器上的 PowerShell 提示符下执行以下命令:

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

如果您不想通过组策略应用更改,这尤其有用。

Ps:要查看当前配置的值是什么,请尝试执行以下命令:

Get-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文