major update to override Write-Output func

This commit is contained in:
2023-10-05 13:11:38 -04:00
parent 31a06a9206
commit bbb4884818
52 changed files with 377 additions and 378 deletions
+24 -24
View File
@@ -8,7 +8,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)
LogMsg " - ${code}"
Write-Output " - ${code}"
$UninstallCodes.Add($code) | Out-Null
}
}
@@ -19,7 +19,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)
LogMsg " - ${prod}"
Write-Output " - ${prod}"
$ProductKeys.Add($prod) | Out-Null
}
}
@@ -28,30 +28,30 @@ Function Get-ProductKeys ([string]$ProductName) {
Function Get-ServiceStatus ([string]$Name) { (Get-Service -Name $Name -ErrorAction SilentlyContinue).Status }
Function Stop-RunningService ([string]$Name) {
If ( $(Get-ServiceStatus -Name $Name) -eq "Running" ) { LogMsg "Stopping : ${Name} service" ; Stop-Service -Name $Name -Force }
If ( $(Get-ServiceStatus -Name $Name) -eq "Running" ) { Write-Output "Stopping : ${Name} service" ; Stop-Service -Name $Name -Force }
}
Function Remove-StoppedService ([string]$Name) {
$s = (Get-ServiceStatus -Name $Name)
If ( $s ) {
If ( $s -eq "Stopped" ) {
LogMsg "Deleting : ${Name} service"
Write-Output "Deleting : ${Name} service"
Start-Process "sc.exe" -ArgumentList "delete ${Name}" -Wait
}
} Else { LogMsg "Not Found: ${Name} service" }
} Else { Write-Output "Not Found: ${Name} service" }
}
Function Stop-RunningProcess ([string]$Name) {
$p = (Get-Process -Name $_ -ErrorAction SilentlyContinue)
If ( $p ) { LogMsg "Stopping : ${Name}.exe" ; $p | Stop-Process -Force }
Else { LogMsg "Not Found: ${Name}.exe is not running"}
If ( $p ) { Write-Output "Stopping : ${Name}.exe" ; $p | Stop-Process -Force }
Else { Write-Output "Not Found: ${Name}.exe is not running"}
}
Function Remove-Path ([string]$Path) {
If ( Test-Path $Path ) {
LogMsg "Deleting : ${Path}"
Write-Output "Deleting : ${Path}"
Remove-Item $Path -Recurse -Force
} Else { LogMsg "Not Found: ${Path}" }
} Else { Write-Output "Not Found: ${Path}" }
}
Function Get-AllExeFiles ([string]$Path) {
@@ -60,39 +60,39 @@ Function Get-AllExeFiles ([string]$Path) {
}
}
LogMsg "Uninstalling Atera agent"
Write-Output "Uninstalling Atera agent"
LogMsg "Mounting HKEY_CLASSES_ROOT registry hive"
Write-Output "Mounting HKEY_CLASSES_ROOT registry hive"
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null
LogMsg "Getting MSI package codes from the uninstall key"
Write-Output "Getting MSI package codes from the uninstall key"
$UninstallCodes = New-Object System.Collections.ArrayList
'AteraAgent' | ForEach-Object { Get-UninstallCodes -DisplayName $_ }
LogMsg "Getting product keys from the list of installed products"
Write-Output "Getting product keys from the list of installed products"
$ProductKeys = New-Object System.Collections.ArrayList
'AteraAgent' | ForEach-Object { Get-ProductKeys -ProductName $_ }
LogMsg "Directories that we may need to delete"
Write-Output "Directories that we may need to delete"
$Directories = @("${Env:ProgramFiles}\ATERA Networks")
$Directories | ForEach-Object { LogMsg " - ${_}" }
$Directories | ForEach-Object { Write-Output " - ${_}" }
LogMsg "Processes that we may need to terminate"
Write-Output "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 { LogMsg " - ${_}.exe" }
$ExeFiles | ForEach-Object { Write-Output " - ${_}.exe" }
LogMsg "Windows services that we may need to stop and/or delete"
Write-Output "Windows services that we may need to stop and/or delete"
$ServiceList = @('AteraAgent')
$ServiceList | ForEach-Object { LogMsg " - ${_}" }
$ServiceList | ForEach-Object { Write-Output " - ${_}" }
LogMsg "Windows Registry keys we may need to delete"
Write-Output "Windows Registry keys we may need to delete"
$RegistryKeys = @('HKLM:SOFTWARE\ATERA Networks')
$RegistryKeys | ForEach-Object { LogMsg " - ${_}" }
$RegistryKeys | ForEach-Object { Write-Output " - ${_}" }
# Uninstall each MSI package code in $UninstallCodes
$UninstallCodes | ForEach-Object { LogMsg "Uninstall: ${_}" ; Start-Process "msiexec.exe" -ArgumentList "/X{${_}} /qn" -Wait }
$UninstallCodes | ForEach-Object { Write-Output "Uninstall: ${_}" ; Start-Process "msiexec.exe" -ArgumentList "/X{${_}} /qn" -Wait }
# Stop services if they're still running
$ServiceList | ForEach-Object { Stop-RunningService -Name $_ }
@@ -112,10 +112,10 @@ $RegistryKeys | ForEach-Object { Remove-Path -Path $_ }
# Delete remaining directories
$Directories | ForEach-Object { Remove-Path -Path $_ }
LogMsg "Unmount HKEY_CLASSES_ROOT registry hive"
Write-Output "Unmount HKEY_CLASSES_ROOT registry hive"
Remove-PSDrive -Name HKCR
LogMsg "Finished uninstalling Atera Agent"
Write-Output "Finished uninstalling Atera Agent"
# Delete this script
Remove-Item $MyInvocation.MyCommand.Path -Force