54
55
56
57
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
|
# File 'lib/resources/wmi.rb', line 54
def params
return @content if defined?(@content)
@content = {}
return @content unless defined?(@options)
args = @options.select { |key, _value| [:class, :namespace, :query, :filter].include?(key) }
params = ''
args.each { |key, value| params += " -#{key} \"#{value.gsub('"', '`"')}\"" }
script = <<-EOH
Filter Aggregate
{
$arr = @{}
$_.properties | % {
$arr.Add($_.name, $_.value)
}
$arr
}
Get-WmiObject #{params} | Aggregate | ConvertTo-Json
EOH
cmd = inspec.powershell(script)
@content = JSON.parse(cmd.stdout)
@content = lowercase_keys(@content)
rescue JSON::ParserError => _e
@content
end
|