Ad Widget

Collapse

I cannot uninstall the zabbix agent from my server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • marcelin
    Junior Member
    • Mar 2023
    • 1

    #1

    I cannot uninstall the zabbix agent from my server

    Good morning gentlemen.
    I deleted the agent zabbix files from my server 2012 so that I could download again, but I can't install another agent zabbix because the old agent zabbix service (stop) is on the machine and there is no other agent zabbix file​
  • Michał Czerniakiewicz
    Junior Member
    • Feb 2023
    • 17

    #2
    Hi marcelin,
    Your zabbix service still exists. What agent version for which OS you are trying to remove?
    Kind regards

    Comment

    • krzysztof.tech
      Junior Member
      • Mar 2023
      • 8

      #3
      Hello, Marceli, first make sure that you have the ability to execute PowerShell scripts. Issue the following command in PowerShell admin: "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUse"

      Below is a PowerShell code that searches for clients with both Zabbix Agent 1 and 2, regardless of whether they are 32 or 64-bit versions, using the keyword "zabbix".
      It removes all related directories and files. In the second part, it checks the registry to make sure that the Zabbix keys have been deleted and then removes the service.




      Code:
      #remove all zabbix cleint and local dir
      
      Write-Host "Detecting current Zabbix Agents"
      Start-Sleep -Seconds 2
      
      $searchString = "Zabbix"
      
      $packages = Get-Package -Name "*$searchString*"
      Clear-Host
      
      if ($packages.Count -eq 0) {
          Write-Host "No packages containin $searchString found"
          Start-Sleep -Seconds 2
      } else {
          Write-Host "The following packages were found::"
          Start-Sleep -Seconds 2
          $packages | Format-Table -AutoSize
      
          foreach ($package in $packages) {
              Uninstall-Package -Name $package.Name -Confirm:$false
              Write-Host "Pakiet $($package.Name) został odinstalowany."
              Start-Sleep -Seconds 2
              Clear-Host
      
              # Delete related directories
              $installPath = $package.InstallLocation
              if ($installPath) {
                  Remove-Item -Path $installPath -Recurse -Force
                  Write-Host "Directory $installPath has been deleted."
                  Start-Sleep -Seconds 2
                  Clear-Host
              } else {
                  Write-Host "Installation directory for package $($package.Name). not found."
                  Start-Sleep -Seconds 2
                  Clear-Host
              }
          }
      }
      Write-Host "Removing Zabbix Agent keys from the registry"
      Start-Sleep -Seconds 2
      Clear-Host
      Remove-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Services\EventLog\Application\Zabbix Agent 2" -Recurse
      Remove-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Services\EventLog\System\Zabbix Agent" -Recurse
      Clear-Host
      Write-Host "Checking registry key positions"
      Start-Sleep -Seconds 2
      Clear-Host
      Get-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Services\EventLog\Application\Zabbix Agent 2" -Recurse
      Get-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Services\EventLog\System\Zabbix Agent" -Recurse
      Clear-Host
      Write-Host "Zabbix Agent registry keys removed"
      Start-Sleep -Seconds 2
      Clear-Host
      Clear-Host
      Write-Host "Removing Zabbix service"
      Start-Sleep -Seconds 2
      sc.exe delete "Zabbix Agent 2"
      Start-Sleep -Seconds 1
      Clear-Host
      sc.exe delete "Zabbix Agent"
      Clear-Host
      Write-Host "Service removed"
      Start-Sleep -Seconds 2
      Clear-Host​

      Comment

      • marcelin
        Junior Member
        • Mar 2023
        • 1

        #4
        Gentlemen managed to remove the zabbix agent.

        thank you for everyone's attention.​

        Comment


        • ChicoJrChad
          ChicoJrChad commented
          Editing a comment
          how can I call a server list in a csv and remove agent from multiple windows servers please?
      Working...