Method: Inspec::Resources::WindowsFeature#info

Defined in:
lib/resources/windows_feature.rb

#infoObject

returns the package description



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
# File 'lib/resources/windows_feature.rb', line 54

def info
  return @cache if !@cache.nil?
  features_cmd = "Get-WindowsFeature | Where-Object {$_.Name -eq '#{@feature}' -or $_.DisplayName -eq '#{@feature}'} | Select-Object -Property Name,DisplayName,Description,Installed,InstallState | ConvertTo-Json"
  cmd = inspec.command(features_cmd)

  @cache = {
    name: @feature,
    type: 'windows-feature',
  }

  # cannot rely on exit code for now, successful command returns exit code 1
  # return nil if cmd.exit_status != 0
  # try to parse json
  begin
    params = JSON.parse(cmd.stdout)
  rescue JSON::ParserError => _e
    return @cache
  end

  @cache = {
    name: params['Name'],
    description: params['Description'],
    installed: params['Installed'],
    type: 'windows-feature',
  }
end