Kaseya Agent Removal Tool

One of the drawbacks of simply uninstalling a Kaseya agent is that it tends to leave behind the kworking directory. This is because of some CSV files in use by the performance counters applied by Monitoring. The PowerShell script does the following:

  1. Determines the unique install directory name for the Kaseya Agent and calls a silent uninstall
  2. Stops and deletes each of the performance counters that were set up by the Kaseya Agent
  3. Deletes the CSV log files for said performance counters (C:\kworking\Klogs\KCTR$xxxx.csv)
  4. Deletes the C:\kworking directory

This is especially handy when the previous MSP was using Kaseya as well.

# Removal of previous Kaseya Agent
# Maintaned by Chris Panagapko
# [email protected]
# ---

# Get our specific agent directory name
$kdir = Get-Childitem 'C:\Program Files (x86)\Kaseya' | Select-Object -ExpandProperty Name

# Silently uninstall Kaseya Agent
Start-Process -FilePath "C:\Program Files (x86)\Kaseya\$kdir\KASetup.exe" -ArgumentList "/s","/r","/g $kdir","/l %temp%\kasetup.log"

# Delete the leftover performance counters
$csvfiles = Get-ChildItem 'C:\kworking\Klogs' | Select-Object -ExpandProperty Name | ForEach-Object {$_.replace('.csv','')}
$counters = Foreach ($a in $csvfiles) {$a.replace('KLOG','KCTR')}

ForEach ($i in $counters) {
    &logman.exe stop $i
    &logman.exe delete $i
}

# Remove the kworking folder
&cmd.exe /c rd /s /q c:\kworking

#SEE YAAAHHH

–Chris

3 Comments

  1. Hello. Thank you for your script!

    We previously used Kaseya RMM, but have since moved to another.

    There are a few other things I would like to see in the PowerShell script, such as:
    – create a transcript of what happened in the script (output)
    – check for any Kaseya services; if so STOP and DISABLE (or remove if possible)
    – remove other Kaseya-created folders found in: C:\Users\%useprofile%\appdata\local\Kaseya, C:\ProgramData\Kaseya, etc.

    I’ve modified your script but I am no PS scripter by any means. If I can email it to you, would you consider checking it?

Leave a Comment