# Removing Agents with no contact over 90 days

**URL:** <https://community.netbeez.net/t/removing-agents-with-no-contact-over-90-days/235>\
**Category:** Remote Worker Agents\
**Tags:** api\
**Created:** [September 21, 2024, 1:21am UTC](https://community.netbeez.net/t/removing-agents-with-no-contact-over-90-days/235 "2024-09-21T01:21:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![joeatffcu](https://avatars.discourse-cdn.com/v4/letter/j/8797f3/32.png) [@joeatffcu](https://community.netbeez.net/u/joeatffcu)\
**Post date:** [September 21, 2024, 1:21am UTC](https://community.netbeez.net/t/removing-agents-with-no-contact-over-90-days/235/1 "2024-09-21T01:21:58Z")

</div>

I am a user not an employee. I like to program in POWERSHELL which is easier for me to understand.  
The following is a small Powershell script which removes remote agents that have not contacted in the last 90 days.  
Before you begin you need the API Token (create it under the settings - read/write permissions) And you need to get windows Powershell 7 or above. Replace the token with your own and replace the server URL with your own.

```PowerShell
##################################################
#Netbeez delete agents over 90 days
#You should run it with Powershell 7 or higher.
##################################################
$Token = "123123123123123123123" | ConvertTo-SecureString -AsPlainText -Force
$date1 = get-date "1/1/1970"
$date2 = (get-date).adddays(-90)
$datets = [math]::truncate((new-timespan -start $date1 -end $date2).totalseconds * 1000.0)
$Uri = "https://netbeez.domain.com/agents?type=beta&filter[active]=false&filter[active_ts][operator]=<&filter[active_ts][value]=$datets"
$agentstr = invoke-restMethod -uri $Uri -method "GET" -Authentication "Bearer" -Token $Token
#Displays a list of the agents to delete
$agentstr.data
#if empty do nothing, otherwise start deleting
if ($agentstr.data.count -gt 0) {
   foreach ($agent in $agentstr.data) {
      $aid=$agent.id
      $url = "https://netbeez.domain.com/agents/"+$aid+"?type=beta"
      $result = invoke-restMethod -uri $url -method "DELETE" -Authentication "Bearer" -Token $Token
      $result
      }
   }
else {
   write-host "No agents found"
   }
pause
#The End

```

---

<div class="post-metadata">

**Author:** ![panickos](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.netbeez.net/panickos/32/8_2.png) [@panickos](https://community.netbeez.net/u/panickos)\
**Post date:** [September 23, 2024, 7:51pm UTC](https://community.netbeez.net/t/removing-agents-with-no-contact-over-90-days/235/2 "2024-09-23T19:51:46Z")

</div>

Hi @joeatffcu! Thank you for your contribution and welcome to the community! I’m sure this will be useful to a lot of users.
