Class: Inspec::Resources::WindowsPkg

Inherits:
PkgManagement show all
Defined in:
lib/resources/package.rb

Overview

Determines the installed packages on Windows Currently we use ‘Get-WmiObject -Class Win32_Product’ as a detection method TODO: evaluate if alternative methods as proposed by Microsoft are still valid: @see: blogs.technet.com/b/heyscriptingguy/archive/2013/11/15/use-powershell-to-find-installed-software.aspx

Instance Attribute Summary

Attributes inherited from PkgManagement

#inspec

Instance Method Summary collapse

Methods inherited from PkgManagement

#initialize

Constructor Details

This class inherits a constructor from Inspec::Resources::PkgManagement

Instance Method Details

#info(package_name) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/resources/package.rb', line 176

def info(package_name)
  # Find the package
  cmd = inspec.command("Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -eq '#{package_name}'} | Select-Object -Property Name,Version,Vendor,PackageCode,Caption,Description | ConvertTo-Json")

  begin
    package = JSON.parse(cmd.stdout)
  rescue JSON::ParserError => _e
    return nil
  end

  {
    name: package['Name'],
    installed: true,
    version: package['Version'],
    type: 'windows',
  }
end