Skip to content

Instantly share code, notes, and snippets.

####Mount an ISO as a drive in Windows
powershell_script 'Mount ISO' do
code <<-EOH
Mount-DiskImage -ImagePath "<<PATH TO ISO>>"
if ($? -eq $True)
{
echo "ISO was mounted Successfully." > #{ENV[TEMP]}\\ISO_Mounted_Successfully.txt
exit 0;
}
##### 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