# Script agent removal

**URL:** <https://discuss.elastic.co/t/script-agent-removal/351443>\
**Category:** Elastic Security\
**Created:** [January 19, 2024, 12:55pm UTC](https://discuss.elastic.co/t/script-agent-removal/351443 "2024-01-19T12:55:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nightingale\_John](https://avatars.discourse-cdn.com/v4/letter/n/ecccb3/32.png) [@Nightingale\_John](https://discuss.elastic.co/u/Nightingale_John)\
**Post date:** [January 19, 2024, 12:55pm UTC](https://discuss.elastic.co/t/script-agent-removal/351443/1 "2024-01-19T12:55:48Z")

</div>

Hi All,

Hopefully this is a quick question for someone.. but I can't find any API to unenroll an agent from Elastic? I've tried a few methods but can't seem to make progress.

Is anyone aware of anyway to script an agent removal?

Thanks  
J

---

<div class="post-metadata">

**Author:** ![yago82](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yago82/32/97755_2.png) [@yago82](https://discuss.elastic.co/u/yago82)\
**Post date:** [January 19, 2024, 1:54pm UTC](https://discuss.elastic.co/t/script-agent-removal/351443/2 "2024-01-19T13:54:41Z")

</div>

> [@Nightingale\_John](#):
>
> Hi All,
> 
> Hopefully this is a quick question for someone.. but I can't find any API to unenroll an agent from Elastic? I've tried a few methods but can't seem to make progress.
> 
> Is anyone aware of anyway to script an agent removal?
> 
> Thanks  
> J

Hi,

probably you have to use this:

```auto
POST /agents/{agentId}/unenroll

```

> **[Fleet APIs | Fleet and Elastic Agent Guide \[8.11\] | Elastic](https://www.elastic.co/guide/en/fleet/8.11/fleet-apis.html#unenrollAgent)**

Regards

---

<div class="post-metadata">

**Author:** ![Nightingale\_John](https://avatars.discourse-cdn.com/v4/letter/n/ecccb3/32.png) [@Nightingale\_John](https://discuss.elastic.co/u/Nightingale_John)\
**Post date:** [January 19, 2024, 2:05pm UTC](https://discuss.elastic.co/t/script-agent-removal/351443/3 "2024-01-19T14:05:45Z")

</div>

Clearly i'm just blind and missed that document... thanks for the link!

---

<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:** [February 16, 2024, 2:06pm UTC](https://discuss.elastic.co/t/script-agent-removal/351443/4 "2024-02-16T14:06:11Z")

</div>

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