如何获取特定 winrm 属性 的值?

How can I get the value of a specific winrm property?

如何才能只获取从下面的 PS 命令返回的值之一?

PS C:\Users\vagrant> winrm get winrm/config/winrs
Winrs
    AllowRemoteShellAccess = true
    IdleTimeout = 7200000
    MaxConcurrentUsers = 10
    MaxShellRunTime = 2147483647
    MaxProcessesPerShell = 25
    MaxMemoryPerShellMB = 300
    MaxShellsPerUser = 30

具体来说,我试图只获取 MaxMemoryPerShellMB 的值。最后,我需要将该值与另一个值进行比较,以便在需要时确保正确设置它。

您可以将 winrm 输出转换为 hashtable:

$winrs = & winrm get winrm/config/winrs |
         Select-Object -Skip 1 |
         Out-String |
         ConvertFrom-StringData

并像这样访问所需的值:

$winrs['MaxMemoryPerShellMB']

或者像这样:

$winrs.MaxMemoryPerShellMB

您可以使用 WS-Management 提供程序获取或设置 WS-Management 配置选项:

(Get-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB).Value 

What is WSMan and how does it compare to winrm?

可以说,它们主要指的是同一件事:

Windows Remote Management (WinRM) is the Microsoft implementation of WS-Management Protocol, a standard Simple Object Access Protocol (SOAP)-based, firewall-friendly protocol that allows hardware and operating systems, from different vendors, to interoperate. Source

winrm get winrm/config的所有选项在WSMan:\localhost\PowerShell路径下可用。其中一些可以使用不同的命名,例如 Shell 而不是 winrs(Window 远程 Shell),但在大多数情况下名称是匹配的。您可以通过标准 PowerShell 命令探索可用的配置选项,例如 dir WSMan:\localhost\.