Last active
September 17, 2020 07:54
-
-
Save Ianvdl/7ee870afdbfec860a0fa8ad3d31debb0 to your computer and use it in GitHub Desktop.
A puppet fact to get software versions on Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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