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
90
91
92
93
94
95
96
|
# File 'lib/inspec/resources/wmi.rb', line 55
def params
return @content if defined?(@content)
@content = {}
return @content unless defined?(@options)
args = @options.select { |key, _value| %i{class namespace query filter}.include?(key) }
params = ""
args.each { |key, value| params += " -#{key} \"#{value.gsub('"', '`"')}\"" }
script = <<-EOH
Function Aggregate {
$propsHash = @{}
ForEach ($wmiObj in $Input) {
ForEach ($wmiProp in $wmiObj.properties) {
If($propsHash.ContainsKey($wmiProp.name)) {
$propsHash[$wmiProp.name].add($wmiProp.value) | Out-Null
} Else {
$propsHash[$wmiProp.name] = [System.Collections.ArrayList]@($wmiProp.value)
}
}
}
$propsHash
}
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
|