Method: Inspec::Resources::WMI#params

Defined in:
lib/resources/wmi.rb

#paramsObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/resources/wmi.rb', line 58

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

  # abort if no options are available
  return @content unless defined?(@options)

  # filter for supported options
  args = @options.select { |key, _value| [:class, :namespace, :query, :filter].include?(key) }

  # convert to Get-WmiObject arguments
  params = ''
  args.each { |key, value| params += " -#{key} \"#{value}\"" }

  # run wmi command and filter empty wmi
  script = "  Filter Aggregate\n  {\n      $arr = @{}\n      $_.properties | % {\n          $arr.Add($_.name, $_.value)\n      }\n      $arr\n  }\n  Get-WmiObject \#{params} | Aggregate | ConvertTo-Json\n  EOH\n\n  # run wmi command\n  cmd = inspec.powershell(script)\n  @content = JSON.parse(cmd.stdout)\n\n  # make all keys case-insensitive\n  @content = lowercase_keys(@content)\nrescue JSON::ParserError => _e\n  @content\nend\n"