# Is it possible to remove unenrolled Agents from Fleet?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-remove-unenrolled-agents-from-fleet/345286>\
**Category:** Kibana\
**Tags:** fleet\
**Created:** [October 18, 2023, 1:05pm UTC](https://discuss.elastic.co/t/is-it-possible-to-remove-unenrolled-agents-from-fleet/345286 "2023-10-18T13:05:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![miela](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@miela](https://discuss.elastic.co/u/miela)\
**Post date:** [October 18, 2023, 1:05pm UTC](https://discuss.elastic.co/t/is-it-possible-to-remove-unenrolled-agents-from-fleet/345286/1 "2023-10-18T13:05:27Z")

</div>

Hi,

I did see the following question: [Is it possible to remove Inactive Agents from Fleet?](https://discuss.elastic.co/t/is-it-possible-to-remove-inactive-agents-from-fleet/334043)

And actually there is an undocumented ( **and potentially dangerous** ) way to remove unenrolled agents. Because I couldn't add my answer there (the thread is closed) I created a new post for people looking for a solution.

---

<div class="post-metadata">

**Author:** ![miela](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@miela](https://discuss.elastic.co/u/miela)\
**Post date:** [October 18, 2023, 1:07pm UTC](https://discuss.elastic.co/t/is-it-possible-to-remove-unenrolled-agents-from-fleet/345286/2 "2023-10-18T13:07:49Z")

</div>

1. Create a service token

```auto
POST /_security/service/elastic/fleet-server/credential/token/delete-agents

```

1. Search the `.fleet-agents` index for the entry you want to delete and get the document `_id`.

2. Delete the fleet entry document (set/replace the ES\_URL, DOC\_ID, and SERVICE\_TOKEN, with the elasticsearch url, the document id to delete, and the in the first step created service token):

```auto
curl --request DELETE \
  --url ${ES_URL}/.fleet-agents-7/_doc/${DOC_ID} \
  --header 'Authorization: Bearer ${SERVICE_TOKEN}' \
  --header 'Content-Type: application/json' \
  --header 'kbn-xsrf: kibana' \
  --header 'x-elastic-product-origin: fleet'

```

1. Delete the service token

```auto
DELETE /_security/service/elastic/fleet-server/credential/token/delete-agents

```

This answer can be merged into the other thread by admins if they want to. Because unfortunately it is no longer possible to answer there. However, I wanted to document my solution for others to find.

---

<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:** [November 15, 2023, 1:08pm UTC](https://discuss.elastic.co/t/is-it-possible-to-remove-unenrolled-agents-from-fleet/345286/3 "2023-11-15T13:08:44Z")

</div>

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