Guest User

Untitled

a guest
Aug 21st, 2025
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. # N-Able Uninstaller
  2. # By Hayden Kirk / Layer3
  3. # v1.2
  4. # 22/07/2024
  5. #
  6. # You can search and use wildcards
  7. # APPLICATION NAME AND PUBLISHER
  8. # IE "*Agent*" = @("N-able Technologies","Second Publisher")
  9. #
  10. # You can also use this with -ReadOnly
  11. # Find-And-ProcessPrograms -softwareMap $softwareMap -ReadOnly
  12.  
  13. $softwareMap = @{
  14. "File Cache Service Agent" = @("N-able")
  15. "Patch Management Service Controller" = @("N-able")
  16. "Request Handler Agent" = @("N-able")
  17. "EcoSystem Agent" = @("Solarwinds MSP")
  18. "Windows Agent" = @("N-able Technologies")
  19. }
  20.  
  21. function Find-And-ProcessPrograms {
  22. param (
  23. [Parameter(Mandatory=$true)]
  24. [System.Collections.Hashtable]$softwareMap,
  25. [switch]$ReadOnly
  26. )
  27.  
  28. $uninstallPaths = @(
  29. 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*',
  30. 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*',
  31. 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*'
  32. )
  33.  
  34. foreach ($pattern in $softwareMap.Keys) {
  35. $allowedVendors = $softwareMap[$pattern]
  36. $found = $false
  37.  
  38. foreach ($path in $uninstallPaths) {
  39. $programs = Get-ItemProperty $path
  40. $matchedPrograms = $programs | Where-Object { $_.DisplayName -like $pattern }
  41.  
  42. foreach ($matchedProgram in $matchedPrograms) {
  43. if ($allowedVendors -contains $matchedProgram.Publisher) {
  44. $found = $true
  45. $uninstallString = $matchedProgram.UninstallString
  46.  
  47. if ($uninstallString -like "MsiExec.exe*") {
  48. $uninstallCommand = "MsiExec.exe"
  49. $uninstallArguments = "/X" + ($uninstallString -replace ".*\{", "{") + " /qn"
  50. } else {
  51. $uninstallCommand = $uninstallString.Trim('"')
  52. $uninstallArguments = "/VERYSILENT"
  53. }
  54.  
  55. if ($ReadOnly) {
  56. Write-Host "Found $($matchedProgram.DisplayName) by $($matchedProgram.Publisher)"
  57. Write-Host "Silent Uninstall String: $uninstallCommand $uninstallArguments"
  58. } else {
  59. Write-Host "Uninstalling $($matchedProgram.DisplayName) by $($matchedProgram.Publisher)..."
  60. Write-Host "Executing: $uninstallCommand $uninstallArguments"
  61. Start-Process -FilePath $uninstallCommand -ArgumentList $uninstallArguments -Wait
  62. }
  63. }
  64. }
  65. }
  66.  
  67. if (-not $found) {
  68. Write-Host "No program found matching the pattern '$pattern' with specified publishers."
  69. }
  70. }
  71. }
  72.  
  73. # Remove software
  74. Find-And-ProcessPrograms -softwareMap $softwareMap
  75.  
  76. # Array of service names to be removed
  77. $serviceNames = @("AutomationManagerAgent", "NCentralLauncher")
  78.  
  79. foreach ($serviceName in $serviceNames) {
  80. # Check if the service exists
  81. $service = Get-Service -Name $serviceName -ErrorAction SilentlyContinue
  82.  
  83. if ($service) {
  84. Write-Output "Service '$serviceName' found. Attempting to delete..."
  85.  
  86. # Attempt to stop the service in case it is running
  87. Stop-Service -Name $serviceName -Force -ErrorAction SilentlyContinue
  88.  
  89. # Wait a bit for the service to stop
  90. Start-Sleep -Seconds 5
  91.  
  92. # Delete the service
  93. sc.exe delete $serviceName
  94.  
  95. Write-Output "Service '$serviceName' has been deleted."
  96. } else {
  97. Write-Output "Service '$serviceName' does not exist."
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment