Class: WinRM::WSMV::WqlQuery

Inherits:
Base
  • Object
show all
Defined in:
lib/winrm/wsmv/wql_query.rb

Overview

WSMV message to query Windows via WQL

Constant Summary

Constants included from Header

Header::RESOURCE_URI_CMD, Header::RESOURCE_URI_POWERSHELL

Constants included from SOAP

SOAP::NS_ADDRESSING, SOAP::NS_CIMBINDING, SOAP::NS_ENUM, SOAP::NS_SCHEMA_INST, SOAP::NS_SOAP_ENV, SOAP::NS_TRANSFER, SOAP::NS_WIN_SHELL, SOAP::NS_WSMAN_CONF, SOAP::NS_WSMAN_DMTF, SOAP::NS_WSMAN_FAULT, SOAP::NS_WSMAN_MSFT

Instance Method Summary collapse

Methods inherited from Base

#build

Methods included from Header

#action_command, #action_delete, #action_enumerate, #action_get, #action_receive, #action_send, #action_signal, #merge_headers, #resource_uri_cmd, #resource_uri_shell, #resource_uri_wmi, #selector_shell_id, #shared_headers

Methods included from SOAP

#namespaces

Constructor Details

#initialize(session_opts, wql) ⇒ WqlQuery

Returns a new instance of WqlQuery.



24
25
26
27
# File 'lib/winrm/wsmv/wql_query.rb', line 24

def initialize(session_opts, wql)
  @session_opts = session_opts
  @wql = wql
end

Instance Method Details

#process_response(response) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/winrm/wsmv/wql_query.rb', line 29

def process_response(response)
  parser = Nori.new(
    parser: :rexml,
    advanced_typecasting: false,
    convert_tags_to: ->(tag) { tag.snakecase.to_sym },
    strip_namespaces: true
  )
  hresp = parser.parse(response.to_s)[:envelope][:body]

  # Normalize items so the type always has an array even if it's just a single item.
  items = {}
  if hresp[:enumerate_response][:items]
    hresp[:enumerate_response][:items].each_pair do |k, v|
      items[k] = v.is_a?(Array) ? v : [v]
    end
  end
  items
end