Skip to content

Instantly share code, notes, and snippets.

@Ianvdl
Last active September 17, 2020 07:54
Show Gist options
  • Save Ianvdl/7ee870afdbfec860a0fa8ad3d31debb0 to your computer and use it in GitHub Desktop.
Save Ianvdl/7ee870afdbfec860a0fa8ad3d31debb0 to your computer and use it in GitHub Desktop.
A puppet fact to get software versions on Windows
$list1 = $(gci -recurse HKLM:Software\Microsoft\Windows\CurrentVersion\Uninstall | gp | select-object displayname,displayversion)
$list2 = $(gci -recurse HKLM:SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall | gp | select-object displayname,displayversion)
$software = $list1 + $list2
#exact names
$names = 'Dropbox', 'RStudio', 'paint.net', 'Puppet Agent', 'Google Chrome', 'Adobe Acrobat DC'
ForEach($name in $names)
{
$item = $($software | where-object {$_.DisplayName -eq $name})
if ($item)
{
Write-Host "version_$($item.DisplayName.Replace(' ', '_').Replace('-', '_'))=$($item.DisplayVersion)"
}
}
#wildcard names - some software names include version numbers, this consolidates them into a single fact name accross versions.
#Note that the wildcard should not match more than one item.
$wildcard_names = 'Firefox', 'Adobe Reader', 'Foxit Reader'
ForEach($name in $wildcard_names)
{
$item = $($software | where-object {$_.DisplayName -like "*$name*"})
if ($item)
{
Write-Host "version_$($name.Replace(' ', '_').Replace('-', '_'))=$($item.DisplayVersion)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment