-
Notifications
You must be signed in to change notification settings - Fork 4
/
Uninstall screenconnect.ps1
47 lines (35 loc) · 1.59 KB
/
Uninstall screenconnect.ps1
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
#Read installation information from the registry and get a list of installed software.
$RegistryLocation = Get-ChildItem "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"
$Name = "screenconnect client (6f88598b921cda40)"
foreach ($RegistryItem in $RegistryLocation)
{
#Check for the software we are looking for...
if ((Get-itemproperty $registryItem.PSPath).DisplayName -like "*$name*")
{
# Get the product code if possible
$productCode = (Get-itemproperty $registryItem.PSPath).ProductCode
# If a product code is available, uninstall using it
if ([string]::IsNullOrEmpty($productCode) -eq $false)
{
$args="/uninstall /q $code"
[diagnostics.process]::start("msiexec", $args).WaitForExit()
$Result = 'Uninstall Attempted'
}
# If there is no product code, try to read the uninstall string
else
{
$uninstallString = (Get-itemproperty $registryItem.PSPath).UninstallString
if ([string]::IsNullOrEmpty($uninstallString) -eq $false)
{
# Grab the product key and create an argument string
$match = [RegEx]::Match($uninstallString, "{.*?}")
$args = "/x $($match.Value) /qn"
[diagnostics.process]::start("msiexec", $args).WaitForExit()
$Result = 'Uninstall Attempted'
}
else { $Result = "Unable to uninstall $name" }
}
}
}
Remove-Item -path "$($env:windir)\servermonitor\packages\screenconnect" -Force -Recurse;
Return $result;