Skip to content

Instantly share code, notes, and snippets.

@ferventcoder
Last active September 11, 2015 07:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ferventcoder/1ff054ded17800b90c6b to your computer and use it in GitHub Desktop.
Save ferventcoder/1ff054ded17800b90c6b to your computer and use it in GitHub Desktop.
MSI package
$ErrorActionPreference = 'Stop';
$packageArgs = @{
packageName = '[[PackageName]]'
unzipLocation = $toolsDir
fileType = 'MSI'
url = '[[Url]]'
url64bit = '[[Url64]]' # 64bit URL here or remove - if installer is both, use $url
silentArgs = "/qn /norestart"
validExitCodes= @(0, 3010, 1641)
# optional, highly recommended
softwareName = '[[PackageName]]*' #part or all of the Display Name as you see it in Programs and Features. It should be enough to be unique
checksum = '[[Checksum]]'
checksumType = '[[ChecksumType]]' #default is md5, can also be sha1
checksum64 = '[[Checksum64]]'
checksumType64= '[[ChecksumType64]]' #default is checksumType
}
Install-ChocolateyPackage @packageArgs
$ErrorActionPreference = 'Stop';
$packageName = '[[PackageName]]'
$softwareName = '[[PackageName]]*' #part or all of the Display Name as you see it in Programs and Features. It should be enough to be unique
$installerType = 'MSI'
$silentArgs = '/qn /norestart'
# https://msdn.microsoft.com/en-us/library/aa376931(v=vs.85).aspx
$validExitCodes = @(0, 3010, 1605, 1614, 1641)
$uninstalled = $false
$local_key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
$machine_key = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*'
$machine_key6432 = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
Get-ItemProperty -Path @($machine_key6432,$machine_key, $local_key) `
-ErrorAction SilentlyContinue `
| ? { $_.DisplayName -like "$softwareName" } `
| Select -First 1 `
| % {
$silentArgs = "$($_.PSChildName) $silentArgs"
$file = ''
Uninstall-ChocolateyPackage -PackageName $packageName `
-FileType $installerType `
-SilentArgs "$silentArgs" `
-ValidExitCodes $validExitCodes `
-File "$file"
$uninstalled = $true
}
if (!($uninstalled)) {
Write-Warning "$packageName has already been uninstalled by other means."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment