-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathecsm-CSUA-Uninstall-Admin.ps1
More file actions
85 lines (69 loc) · 2.94 KB
/
Copy pathecsm-CSUA-Uninstall-Admin.ps1
File metadata and controls
85 lines (69 loc) · 2.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<#
.SYNOPSIS
Script to uninstall all instances of the Cloud Signature Update Agent
.DESCRIPTION
This script is designed to be deployed via management software to all machines to remove the agent.
It can be run manually via PowerShell.
When run in the Admin/System context, it may not remove the ALLUSER MSI installations as these are deployed as admin
.NOTES
Date: 8th July 2020
.PRODUCTS
Exclaimer Cloud - Signatures for Office 365
.REQUIREMENTS
- Added commands to remove MSI installations
- Added commands to remove Click Once Installations
#>
# Click Once uninstall
$app = "Exclaimer Cloud Signature Update Agent"
# -------------------------------
# Ensure the script is running with elevated permissions
# -------------------------------
$isAdmin = ([Security.Principal.WindowsPrincipal] `
[Security.Principal.WindowsIdentity]::GetCurrent()
).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
Write-Host 'Elevated privileges are required. Relaunching as administrator...'
Start-Sleep -Seconds 3
exit 1
}
# -------------------------------
# Remove Exclaimer Agent Run keys (all users)
# -------------------------------
function RemoveUserRunKey {
param($sid)
$runPath = "Registry::HKEY_USERS\$sid\Software\Microsoft\Windows\CurrentVersion\Run"
if (Test-Path $runPath) {
Remove-ItemProperty -Path $runPath -Name "*Cloud Signature Update Agent" -ErrorAction SilentlyContinue
Write-Host "Removed Run key for user hive $sid"
}
}
$userHives = Get-ChildItem 'Registry::HKEY_USERS' -ErrorAction SilentlyContinue |
Where-Object { $_.PSChildName -match '^S-' -and $_.PSChildName.Length -ge 30 -and $_.PSChildName -notmatch '_Classes$' }
foreach ($hive in $userHives) {
RemoveUserRunKey -sid $hive.PSChildName
}
$runKeyMachine = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Run"
Remove-ItemProperty -Path $runKeyMachine -Name "Cloud Signature Update Agent" -ErrorAction SilentlyContinue
Write-Host "Removed HKLM Run key for Cloud Signature Update Agent"
$InstalledApplicationNotMSI = Get-ChildItem HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall | foreach-object {Get-ItemProperty $_.PsPath}
$UninstallString = $InstalledApplicationNotMSI | Where-Object { $_.displayname -match "$app" } | Select-Object UninstallString
if (!$UninstallString.UninstallString) {
Write-Output "No ClickOnce agent found"
}
if ($UninstallString.UninstallString) {
$wshell = new-object -com wscript.shell
$selectedUninstallString = $UninstallString.UninstallString
$wshell.run("cmd /c $selectedUninstallString")
Start-Sleep 5
$wshell.sendkeys("`"OK`"~")
Write-Output "ClickOnce agent removed"
}
# MSI Uninstall
$MyApp = Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -eq "Exclaimer Cloud Signature Update Agent"}
if (!$MyApp) {
Write-Output "No MSI installed agent found"
}
if ($MyApp) {
$MyApp.Uninstall() | Out-Null
Write-Output "MSI installed agent removed"
}