Remote BESRemove via Powershell

I would like to share the below powershell script for running BESRemove remotely. This is useful for problematic clients that are not reporting to the console and cannot be targeted by “Fixlet 219: TROUBLESHOOTING: Uninstall BES Client”

$computers = Get-Content C:\computers.txt
$besremove = "C:\BESRemove.exe"

foreach ($computer in $computers)
{
###Copy BESRemove.exe on target computers listed on computers.txt
Copy-Item $besremove -Destination "\\$computer\C$\ProgramData"

Write-Host "BESRemove.exe copied on $computer" -ForegroundColor Green

###Stop BESClientHelper service (if existing)
If ((Get-Service -Name besclienthelper -ComputerName $computer).Status -eq 'Running') {

        Get-Service -Name besclienthelper -ComputerName $computer | Stop-Service
        }

###Stop BESClient service
Get-Service -Name besclient -ComputerName $computer | Stop-Service

###Run BESRemove.exe
Invoke-Command -ComputerName $computer -ScriptBlock { & cmd.exe /c "C:\ProgramData\BESRemove.exe" '/silent' '/force' '/client'}

###Delete BigFix Enterprise Folder
Invoke-Command -ComputerName $computer -ScriptBlock { & cmd.exe /c rd /s /q "C:\Program Files (x86)\BigFix Enterprise"}

###Delete BESRemove.exe
Invoke-Command -ComputerName $computer -ScriptBlock { & cmd.exe /c del /f /q "C:\ProgramData\BESRemove.exe"}

Write-Host "BESClient Successfully Removed on $computer" -ForegroundColor Green
}
5 Likes