/build/static/layout/Breadcrumb_cap_w.png

Old Kace agent removal

Hey guys, I am new here and wanted to provide this script for anyone else who might be in my position but I didnt know where to post it. Hope you guys will be kind enough to move the post instead of yelling at me for posting it in the wrong section. Situation i was in is that at I deployed the newest version of K1000 and deployed agents via GPO. Shortly after i found out that about half the machines had old version of the agent deployed and it prevented new one from being installed. Old agent didn't want to report to the new appliance even tho the name/ip was the same. After looking through a few posts i found some scripts to remove the old agent but neither one of them would be any kind of selective so I wrote my own and wanted to share to help others out.
While I am running this script in two parts It can be combined into a single script, I just wanted control and to review the list of machines it'll hit before it starts uninstalling anything. I am not a powershell guru so I am sure i mad emistakes and feedback is welcomed.
fFirst part of the script is to find all machines that have old agent, since I was going from 6.x (pre-quest) it was done easily by  searching through AD and checking service names and dumping machine names into a txt file.

Get-ADComputer -Properties * -Filter * -SearchBase "********" | foreach { if (Get-Service -ComputerName $_.name -DisplayName "dell kace*") {echo $_.name}} >> Feed-list.txt 

 this piece could easily be caught into a variable instead and used in for each loop instead of feeding foreach loop from a text file. But like i said, i wanted to review the list first. Similar check could be done by reading c:\programdata\amp.conf for agent version but as this was easier in my case i went with path of least resistance.

This is the actual install piece of the script. It'll check OS architecture  and execute on proper path.

$list = Get-Content .\Feed-list.txt

foreach ($item in $list) {

Remove-Variable amprem32
Remove-Variable amprem64
Remove-Variable checktemp
Remove-Variable arch

$arch = (Get-WmiObject Win32_OperatingSystem -ComputerName $item ).OSArchitecture
$amprem64 = test-path "\\$item\c$\temp\amremove64.cmd"
$amprem32 = test-path "\\$item\c$\temp\amremove32.cmd"
$checktemp = test-path "\\$item\c$\temp"

if ($arch -eq "64-bit") {

if (-not $checktemp) {mkdir \\$item\c$\temp
    Copy-Item .\amremove64.cmd \\$item\c$\temp} else { if (-not $amprem64) {Copy-Item .\amremove64.cmd \\$item\c$\temp}}
    write-host running 64-bit
    .\PsExec.exe \\$item -h -accepteula cmd /c c:\temp\amremove64.cmd
    Remove-Item \\$item\c$\temp\amremove64.cmd
    }
        else {
        if (-not $checktemp) {mkdir \\$item\c$\temp
    Copy-Item .\amremove32.cmd \\$item\c$\temp} else { if (-not $amprem32) {Copy-Item .\amremove32.cmd \\$item\c$\temp}}
    write-host running 32-bit
    .\PsExec.exe \\$item -h -accepteula cmd /c c:\temp\amremove32.cmd
    Remove-Item \\$item\c$\temp\amremove32.cmd
    }
    }


Two CMD's it copies are the basic Kace CMD's

cd "C:\Program Files (x86)\dell\kace" - change path for 32bit CMD
AMPTools.exe uninstall all



to search amp.conf file for file version instead of get-service name use select-string in foreach with desired pattern. It'll look something like this
Get-ADComputer -Properties * -Filter * -SearchBase "********" | foreach { if (select-string -Path \\$_.name\C$\ProgramData\dell\KACE\amp.conf -pattern "serverversion=6") {echo $_.name}} >> Feed-list.txt


Comments

This post is locked

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ