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



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/resources/package.rb', line 192

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