Method: Inspec::Resources::WMI#info

Defined in:
lib/resources/wmi.rb

#infoObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/resources/wmi.rb', line 52

def info
  return @content if defined?(@content)
  @content = {}

  # we should abort execution, if wmi class is not given or wmi resource is
  # executed on a non-windows system
  return @content if @wmiclass.nil?

  # optional params
  cmd_namespace = "-namespace #{@wminamespace}" unless @wminamespace.nil?
  cmd_filter = "-filter \"#{@wmifilter}\"" unless @wmifilter.nil?

  # run wmi command
  cmd = inspec.command("Get-WmiObject -class #{@wmiclass} #{cmd_namespace} #{cmd_filter} | ConvertTo-Json")
  @content = JSON.parse(cmd.stdout)
rescue JSON::ParserError => _e
  @content
end