# Uninstalling Elastic Agent 8.8.2 on Windows Devices

**URL:** <https://discuss.elastic.co/t/uninstalling-elastic-agent-8-8-2-on-windows-devices/356224>\
**Category:** Elastic Agent\
**Created:** [March 27, 2024, 5:46am UTC](https://discuss.elastic.co/t/uninstalling-elastic-agent-8-8-2-on-windows-devices/356224 "2024-03-27T05:46:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KrisD](https://avatars.discourse-cdn.com/v4/letter/k/a587f6/32.png) [@KrisD](https://discuss.elastic.co/u/KrisD)\
**Post date:** [March 27, 2024, 5:46am UTC](https://discuss.elastic.co/t/uninstalling-elastic-agent-8-8-2-on-windows-devices/356224/1 "2024-03-27T05:46:02Z")

</div>

I’m attempting to uninstall Elastic Agent version 8.8.2 from Windows devices using a script. While the script successfully uninstalls the software on the first attempt, it doesn’t delete the installation folder. I have to run the script a second time to remove the folder. Could anyone assist me in modifying the script so that it uninstalls the software and removes the folder in one go?

```auto
$processes=@(

'filebeat',

'metricbeat',

'fleet-server',

'elastic-endpoint',

'elastic-agent'

)

$runningProcesses = Get-Process | select ProcessName

foreach ($process in $processes)

    {

    if ($process -in $runningProcesses.ProcessName)

        {

        Write-Output "$process found"

        Stop-Process -Name $process -Force -ErrorAction SilentlyContinue

        }

    }

if (Test-Path "$($env:ProgramFiles)\elastic\agent\elastic-agent.exe")

    {

    Start-Sleep -Seconds 5

    $directoryName = Get-ChildItem -Path "C:\Program Files\Elastic\Agent\data\" | where {$_.name -like "elastic*"}

    Start-Process -FilePath "$($env:ProgramFiles)\elastic\agent\data\$($directoryName.Name)\elastic-agent.exe" -ArgumentList "uninstall --force"

    Start-Sleep -Seconds 5

    }

if (Test-Path -Path "C:\Program Files\Elastic")

    {

    Write-Output "Path still present - attempting removal."

    Remove-Item -Path "C:\Program Files\Elastic\Agent" -Recurse -Force -ErrorAction SilentlyContinue

    }

 

```

---

<div class="post-metadata">

**Author:** ![KrisD](https://avatars.discourse-cdn.com/v4/letter/k/a587f6/32.png) [@KrisD](https://discuss.elastic.co/u/KrisD)\
**Post date:** [April 2, 2024, 3:52am UTC](https://discuss.elastic.co/t/uninstalling-elastic-agent-8-8-2-on-windows-devices/356224/2 "2024-04-02T03:52:13Z")

</div>

any update ?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 30, 2024, 3:52am UTC](https://discuss.elastic.co/t/uninstalling-elastic-agent-8-8-2-on-windows-devices/356224/3 "2024-04-30T03:52:46Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
