Created
November 6, 2017 02:20
-
-
Save keyrage/efaab68cff30c98242225cd94c761214 to your computer and use it in GitHub Desktop.
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
##### Check if an application is installed. | |
# In a lot of cases an MSI doesn't properly get detected by the Chef windows_package resource or is some pther package type. The best approach is to use a guard which checks the uninstaller regkey to check that the package and version exist as a Guard. Note: Replace the items inside the "<< >>" notation with the appropriate name and version. I'll usually use an attribute to allow for changes to be applied at an environment or role level. | |
#### X64 bit detection or native 32 bit | |
not_if <<-EOH | |
$installed=Get-ItemProperty HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall*|where {$_.DisplayName -eq \"<<SOFTWARE DISPLAY NAME>>\"} | |
if ($installed) { | |
if([system.version]$installed.DisplayVersion -ge [system.version]\"<<SOFTWARE VERSION NUMBER>>\"){$true}else{$false} | |
} | |
else | |
{$false} | |
EOH | |
##### X86 bit detection on a X64 bit architecture | |
not_if <<-EOH | |
$installed=Get-ItemProperty HKLM:\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall*|where {$_.DisplayName -eq \"<<SOFTWARE DISPLAY NAME>>\"} | |
if ($installed) { | |
if([system.version]$installed.DisplayVersion -ge [system.version]\"<<SOFTWARE VERSION NUMBER>>\"){$true}else{$false} | |
} | |
else | |
{$false} | |
EOH | |
#Check if an ISO is mounted. | |
not_if "((gwmi -Class Win32_LogicalDisk | Where-Object {$_.VolumeName -eq \"<<VOLUME NAME>>\"}).VolumeName -eq \"<<VOLUME NAME>>\")" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note Guards that use powershell code need the guard_interpreter set to :powershell_script otherwise they will silently fail.