# Prevent duplicates when enrolling, scripted unenroll?

**URL:** <https://discuss.elastic.co/t/prevent-duplicates-when-enrolling-scripted-unenroll/277331>\
**Category:** Beats\
**Tags:** fleet\
**Created:** [June 29, 2021, 9:53am UTC](https://discuss.elastic.co/t/prevent-duplicates-when-enrolling-scripted-unenroll/277331 "2021-06-29T09:53:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tjfred](https://avatars.discourse-cdn.com/v4/letter/t/e9c0ed/32.png) [@tjfred](https://discuss.elastic.co/u/tjfred)\
**Post date:** [June 29, 2021, 9:53am UTC](https://discuss.elastic.co/t/prevent-duplicates-when-enrolling-scripted-unenroll/277331/1 "2021-06-29T09:53:14Z")

</div>

Hello,

Testing Fleet here on our Cloud deployment. I'm building an installer for Elastic Agent that gives us greater control when deploying to endpoints via our management system.

My questions:

1. Agent allows enrolling more than once, duplicates then show in the list of agents. Any advice on how to prevent this? I was thinking maybe to check the output of `elastic-agent status` before installing/enrolling, but perhaps there is a better way?

2. How to unenroll an agent using the agent itself rather than manually in Kibana? This may help with option 1), but would also be useful to build into my uninstaller. The uninstall command for `elastic-agent` does uninstall everything, but doesn't unenroll the agent from Fleet.

Any help would be appreciated, thanks!

---

<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:** [July 27, 2021, 11:53am UTC](https://discuss.elastic.co/t/prevent-duplicates-when-enrolling-scripted-unenroll/277331/2 "2021-07-27T11:53:31Z")

</div>

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