Remove Kaseya Agent
Overview
This script attempts the complete removal of Kaseya Agent from Windows systems, ensuring all related services, processes and performance counters are removed.
Usage
Option 1: Run directly from the web
Run the following command in an elevated PowerShell session:
iex (iwr -UseBasicParsing https://techdocsoffline.com/powershell-snippets/RemoveKaseyaAgent.ps1)
Option 2: Download and run locally
- Download the script:
Invoke-WebRequest -Uri https://techdocsoffline.com/powershell-snippets/RemoveKaseyaAgent.ps1 -OutFile RemoveKaseyaAgent.ps1
- Run the script with administrative privileges:
.\RemoveKaseyaAgent.ps1
Script Details
# =============================================================================# Script Name: Remove Kaseya Agent# Version: 1.0.0# =============================================================================## DESCRIPTION:# Removes the Kaseya Agent from a Windows system.## DISCLAIMER:# This script is provided "AS IS" without warranties of any kind.# Always review scripts from the internet before executing them.## =============================================================================
# Check if the script is running with administrative privilegesif (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) { Write-Host "This script must be run as an administrator." -ForegroundColor Red exit}
$logFile = $env:TEMP + "kaseya_log.log"$uninstallCompleteString = "Agent setup finished!" # String to look for during uninstall to determine uninstall complete
# Clean up KCTR$ data collectors firstWrite-Host "Attempting to stop delete KCTR$ data collector sets"
# Query user-defined data collector sets$logmanQuery = logman query
# Find any lines that match *KCTR$*$logmanLineOutput = $logmanQuery.split("`n")$kctrLines = $logmanLineOutput | Where-Object {$_ -like "*KCTR$*"}
# Parse through resultsforeach ($kctrLine in $kctrLines) { $kctrCounterName = $kctrLine.Split(" ")[0]
Write-Output "Attempting to stop $kctrCounterName" logman stop $kctrCounterName
Write-Output "Attempting to delete $kctrCounterName" logman delete $kctrCounterName}
# Start Kaseya uninstallation processWrite-Output "Starting Kaseya Agent uninstallation"
# Get agent under Kaseya directory$agentDirectory = Get-ChildItem "C:\Program Files (x86)\Kaseya" | Select-Object -ExpandProperty Name
# Start uninstallationStart-Process -FilePath "C:\Program Files (x86)\Kaseya\$agentDirectory\KASetup.exe" -ArgumentList "/s","/r","/g $agentDirectory","/l $logFile"
# Wait until log file existsWrite-Host "Waiting for the Kaseya Agent uninstall log file to exist"while (-not (Test-Path $logFile)) { Write-Host "Log file does not exist... Waiting..." Start-Sleep -s 1 # Wait 1 second before next attempt}
# Watch uninstall processGet-Content -Path $logFile -Wait | ForEach-Object { Write-Host "LOG: $_" if ($_ -match $uninstallCompleteString) { Write-Host "Agent has been uninstalled. Found string: $_" Write-Output "Any KCTR$ data collector sets have been removed, manual cleanup may be required." Write-Output "The default working directory for Kaseya agent is C:\kworking\Klogs, however it may have been renamed." Write-Output "You may see the working directory in the uninstall log above, look for ""AgentWorking Folder = <directory>""" Write-Output "You may safely remove these directories." break }}
Parameters
No parameters are required for this script.
Examples
# Run the script.\RemoveKaseyaAgent.ps1