more verbose output
This commit is contained in:
+16
-10
@@ -9,7 +9,7 @@ Function Get-UninstallCodes ([string]$DisplayName) {
|
||||
If ( $(Get-ItemProperty -Path $_.PSPath -Name 'DisplayName' -ErrorAction SilentlyContinue) -and ($(Get-ItemPropertyValue -Path $_.PSPath -Name 'DisplayName' -ErrorAction SilentlyContinue) -eq $DisplayName) ) {
|
||||
$str = (Get-ItemPropertyValue -Path $_.PSPath -Name 'UninstallString')
|
||||
$code = $str.Substring(($str.Length - 37),36)
|
||||
CLogMsg "Found : ${code}"
|
||||
CLogMsg " - ${code}"
|
||||
$UninstallCodes.Add($code) | Out-Null
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ Function Get-ProductKeys ([string]$ProductName) {
|
||||
Get-ChildItem -Path 'HKCR:Installer\Products' | ForEach-Object {
|
||||
If ( $(Get-ItemProperty -Path $_.PSPath -Name 'ProductName' -ErrorAction SilentlyContinue) -and ($(Get-ItemPropertyValue -Path $_.PSPath -Name 'ProductName' -ErrorAction SilentlyContinue) -eq $ProductName) ) {
|
||||
$prod = $_.PSPath.Substring($_.PSPath.Length - 32)
|
||||
CLogMsg "Found : ${prod}"
|
||||
CLogMsg " - ${prod}"
|
||||
$ProductKeys.Add($prod) | Out-Null
|
||||
}
|
||||
}
|
||||
@@ -61,37 +61,43 @@ Function Get-AllExeFiles ([string]$Path) {
|
||||
}
|
||||
}
|
||||
|
||||
CLogMsg "Uninstalling Atera agent"
|
||||
|
||||
# Test if the custom function LogMsg is available in the current scope
|
||||
If ( Get-Command 'LogMsg' -ErrorAction SilentlyContinue ) { $CUSTOM_LOG_AVAILABLE = $true } Else { $CUSTOM_LOG_AVAILABLE = $false }
|
||||
|
||||
# Mount HKEY_CLASSES_ROOT registry hive
|
||||
CLogMsg "Mounting HKEY_CLASSES_ROOT registry hive"
|
||||
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null
|
||||
|
||||
#######
|
||||
# START: Information gathering
|
||||
#######
|
||||
|
||||
# Get MSI package codes from the uninstall key
|
||||
CLogMsg "Getting MSI package codes from the uninstall key"
|
||||
$UninstallCodes = New-Object System.Collections.ArrayList
|
||||
'AteraAgent' | ForEach-Object { Get-UninstallCodes -DisplayName $_ }
|
||||
|
||||
# Get product keys from the list of installed products
|
||||
CLogMsg "Getting product keys from the list of installed products"
|
||||
$ProductKeys = New-Object System.Collections.ArrayList
|
||||
'AteraAgent' | ForEach-Object { Get-ProductKeys -ProductName $_ }
|
||||
|
||||
# Define all the directories we'll need to cleanup at the end of this script
|
||||
CLogMsg "Directories that we may need to delete"
|
||||
$Directories = @("${Env:ProgramFiles}\ATERA Networks")
|
||||
$Directories | ForEach-Object { CLogMsg " - ${_}" }
|
||||
|
||||
# Get all possible relevant exe files so we can make sure they're closed later on
|
||||
CLogMsg "Processes that we may need to terminate"
|
||||
$ExeFiles = New-Object System.Collections.ArrayList
|
||||
$Directories | ForEach-Object { Get-AllExeFiles -Path $_ }
|
||||
$ExeFiles.Add('reg') | Out-Null
|
||||
$ExeFiles | ForEach-Object { CLogMsg " - ${_}.exe" }
|
||||
|
||||
# Define a list of services we need to stop and delete (if necessary)
|
||||
CLogMsg "Windows services that we may need to stop and/or delete"
|
||||
$ServiceList = @('AteraAgent')
|
||||
$ServiceList | ForEach-Object { CLogMsg " - ${_}" }
|
||||
|
||||
# Define a list of registry keys we'll delete
|
||||
CLogMsg "Windows Registry keys we may need to delete"
|
||||
$RegistryKeys = @('HKLM:SOFTWARE\ATERA Networks')
|
||||
$RegistryKeys | ForEach-Object { CLogMsg " - ${_}" }
|
||||
|
||||
#######
|
||||
# END: Information gathering
|
||||
@@ -112,7 +118,7 @@ $ServiceList | ForEach-Object { Remove-StoppedService -Name $_ }
|
||||
# Delete products from MSI installer registry
|
||||
$ProductKeys | ForEach-Object { Remove-Path -Path "HKCR:Installer\Products\${_}" }
|
||||
|
||||
# Unmount HKEY_CLASSES_ROOT registry hive
|
||||
CLogMsg "Unmount HKEY_CLASSES_ROOT registry hive"
|
||||
Remove-PSDrive -Name HKCR
|
||||
|
||||
# Delete registry keys
|
||||
|
||||
Reference in New Issue
Block a user