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

3.5k views Asked by At

How do I go about getting only one of the values returned from the PS command below?

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

Specifically, I'm trying to to get only the value of MaxMemoryPerShellMB. Ultimately I need to compare that value to another value so I can be sure to set it correctly if needed.

2

There are 2 answers

1
user4003407 On BEST ANSWER

You can use WS-Management provider to get or set WS-Management configuration options:

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

What is WSMan and how does it compare to winrm?

You can say, that them both refer mostly to the same thing:

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

All the options of winrm get winrm/config available under WSMan:\localhost\ PowerShell path. Some of them can use different naming, like Shell instead of winrs (Window Remote Shell), but in most cases names match. You can explore available configuration options by standard PowerShell commands, like dir WSMan:\localhost\.

0
Ansgar Wiechers On

You could convert the winrm output to a hashtable:

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

and access the desired value like this:

$winrs['MaxMemoryPerShellMB']

or like this:

$winrs.MaxMemoryPerShellMB