-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathUninstallMSIbyGUID.ps1
More file actions
60 lines (50 loc) · 1.94 KB
/
UninstallMSIbyGUID.ps1
File metadata and controls
60 lines (50 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<#
.SYNOPSIS
Uninstall MSI by GUID
.DESCRIPTION
Uninstall an MSI installed application by specifying its GUID
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2017 v5.4.145
Created on: 2/23/2018 11:58 AM
Created by: Mick Pletcher
Filename: UninstallMSIbyGUID.ps1
===========================================================================
#>
[CmdletBinding()]
param ()
function Uninstall-MSIbyGUID {
<#
.SYNOPSIS
Uninstall-MSIByGUID
.DESCRIPTION
Uninstalls an MSI application using the GUID
.PARAMETER GUID
Associated GUID with the application
.PARAMETER Switches
MSI switches
#>
[CmdletBinding()]
param
(
[ValidateNotNullOrEmpty()][String]$GUID,
[ValidateNotNullOrEmpty()][String]$Switches
)
[string]$DisplayName = ((Get-ChildItem -Path REGISTRY::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products).Name | Foreach-object { Get-ChildItem REGISTRY::$_ } | ForEach-Object { If ($_ -like "*InstallProperties*") { Get-ItemProperty -path REGISTRY::$_ } } | Where-Object { $_.UninstallString -like "*" + $GUID + "*" }).DisplayName
If (($DisplayName -ne "") -and ($DisplayName -ne $null)) {
$Executable = $Env:windir + "\system32\msiexec.exe"
$Parameters = "/x" + [char]32 + $GUID + [char]32 + $Switches
Write-Host "Uninstall"$DisplayName.Trim()"....." -NoNewline
$ErrCode = (Start-Process -FilePath $Executable -ArgumentList $Parameters -Wait -Passthru).ExitCode
If (($ErrCode -eq 0) -or ($ErrCode -eq 3010)) {
Write-Host "Success" -ForegroundColor Yellow
} elseIf ($ErrCode -eq 1605) {
Write-Host "Not Present" -ForegroundColor Green
} else {
Write-Host "Failed with error code "$ErrCode -ForegroundColor Red
Exit $ErrCode
}
}
}
#Java 8 Update 161 Example
Uninstall-MSIbyGUID -GUID "{26A24AE4-039D-4CA4-87B4-2F32180161F0}" -Switches "/qb- /norestart"