mirror of
https://github.com/inspec/inspec
synced 2025-02-17 06:28:40 +00:00
use powershell function for registry key
This commit is contained in:
parent
571bc14742
commit
1faa68732e
1 changed files with 18 additions and 11 deletions
|
@ -117,18 +117,25 @@ module Inspec::Resources
|
|||
|
||||
# load registry key and all properties
|
||||
script = <<-EOH
|
||||
$reg = Get-Item 'Registry::#{path}'
|
||||
$object = New-Object -Type PSObject
|
||||
$reg.Property | ForEach-Object {
|
||||
$key = $_
|
||||
if ("(default)".Equals($key)) { $key = '' }
|
||||
$value = New-Object psobject -Property @{
|
||||
"value" = $reg.GetValue($key);
|
||||
"type" = $reg.GetValueKind($key);
|
||||
}
|
||||
$object | Add-Member –MemberType NoteProperty –Name $_ –Value $value
|
||||
$path = '#{path}'
|
||||
Function Get-InSpec-RegistryKey($path) {
|
||||
$fullpath = 'Registry::' + $path
|
||||
$reg = Get-Item $fullpath
|
||||
|
||||
# convert properties
|
||||
$properties = New-Object -Type PSObject
|
||||
$reg.Property | ForEach-Object {
|
||||
$key = $_
|
||||
if ("(default)".Equals($key)) { $key = '' }
|
||||
$value = New-Object psobject -Property @{
|
||||
"value" = $reg.GetValue($key);
|
||||
"type" = $reg.GetValueKind($key);
|
||||
}
|
||||
$properties | Add-Member –MemberType NoteProperty –Name $_ –Value $value
|
||||
}
|
||||
$properties
|
||||
}
|
||||
$object | ConvertTo-Json
|
||||
Get-InSpec-RegistryKey($path) | ConvertTo-Json
|
||||
EOH
|
||||
|
||||
cmd = inspec.powershell(script)
|
||||
|
|
Loading…
Add table
Reference in a new issue