jborean93/pypsrp

enumerate/configure WSMan with psrp.wsman.WSMan

Closed this issue · 2 comments

Am I completely off-base here with this module?

It seems like this could work, and I would like to use your module to query / configure WSMan locally / remotely.

My current project involves adding an HTTPS listener after the appropriate certificates are created and imported to the local machine certificate store and although the:

  • winrm create winrm/config/Listener?Address=*+Transport=HTTPS @{Hostname="host_name";CertificateThumbprint="certificate_thumbprint"}

... works, but I wanted something more pythonic than shelling out to sys.system(command) or running powershell

import pypsrp.wsman
  
wsman = pypsrp.wsman.WSMan(
    "someserver",
    ssl=True,
    auth="ntlm",
    encryption="always",
    username="someuser",
    password="password",
    cert_validation=False)

data = wsman.enumerate(resource_uri="winrm/config/listener", resource=None)

# error: WSManFaultError: Received a WSManFault message. (Code: 2150858811, Machine: someserver, Reason: The WS-Management service cannot process the request. The resource URI (winrm/config/listener) was not found in the WS-Management catalog. The catalog contains the metadata that describes resources, or logical endpoints.)

I was hoping for a tiny point in the right direction if it is possible with this module as I didn't find any examples.

Also, I was trying to simulate this powershell.
Get-WSManInstance -Enumerate -ResourceURI winrm/config/listener

Please and Thank You for any replies and thank you for your continued work on pypsrp. I've been a fan for a while now.

Steven

Hey just a heads up I'll be taking some time off for the coming weeks so probably won't be able to look into this soon. One thing I would suggest is doing the same Get-WSManInstance call but with a remote host so you can see what the resource URI used is there. There's a good chance you just need to use the full URI rather than the path at the end.

Thanks for the nudge!!!

selector_set = pypsrp.wsman.SelectorSet()
selector_set.add_option("Transport", "HTTP")
selector_set.add_option("Address", "*")
element = wsman.get(resource_uri="http://schemas.microsoft.com/wbem/wsman/1/config/listener", resource=None, selector_set=selector_set)

# produces a valid element tree.

Now I just need to get familiar with the syntax, the data provided, and the ElementTree object. HUGE THANKS!

Steven