Skip to main content

Overview

Remove stagnant agents based on a set of filters passed in via a JSON file. Logs the removed agents in a file in the same directory as the executable (yyyyMMddhhmmssfff_stagnantAgents.log). Email notifications can be sent via the procedure.

Requirements

  • .NET 8

Dependencies

Process

Gets a list of agents that meet the set criteria (offline for $OfflineDays days, not in $MachineGroupException groups, etc.) and runs the VSAAPI function Remove-VsaAgent, removing them from the VSA without first uninstalling the agent. Exclusion filters can be applied for OsType, OsInfo (Build caption), IPAddress, Mac Address, Country, Domain, and Workgroup. Filters are individually applied; applying more than one filter will remove BOTH pools from the removal list. For example, providing -OsTypeExclusion '10' and -DomainWorkgroupExclusion 'proval' will retain ALL Windows 10 machines from the list, AND ALL machines on the ProVal domain or Workgroup.

Payload Usage

./Remove-VsaStagnantAgent.ps1 -BaseURL https://vsa.provaltech.com -VsaUserName apiServiceAccount -RestApiToken abcd-efgh-ijkl-mnop -OfflineDays 30 -MachineGroupException proval.development -OsTypeException 11

Removes agents offline for 30 days in all groups except proval.development. Does not remove any endpoint running Windows 11.

Parameters

ParameterRequiredDefaultTypeDescription
BaseURLTrueStringVSA URL
VsaUserNameTrueStringUser with API Access
RestApiTokenTrueStringREST API Token for User
OfflineDaysFalse60IntAgent Idle Days for removal
MachineGroupExceptionFalseString ArrayGroups to exclude from agent removal
OsTypeExclusionFalseString ArrayExclude agents from removal based on their OsType Field. This can be a partial match. Example Syntax: 10 (Windows 10), 2022 (Windows Server 2022), Mac (Mac OS X, All Versions)
OsInfoExclusionFalseString ArrayExclude agents from removal based on their OsInfo Field. This can be a partial match. Example Syntax: Enterprise, Professional, Server, 19077 (All Windows Machines at build 19077), 19H2026 (All Mac OS X 10.15.7 machines)
ComputerNameExclusionFalseString ArrayExclude agents from removal based on Machine Name. This can be a partial match.
IPAddressExclusionFalseString ArrayExclude agents from removal based on IP Address. This can be a partial address.
MacAddrExclusionFalseString ArrayExclude agents from removal based on MAC Address. This can be a partial address.
CountryExclusionFalseString ArrayExclude agents from removal based on Country. This can be a partial match.
DomainWorkgroupExclusionFalseString ArrayExclude agents from removal based on Domain or Workgroup Name. This can be a partial match.

Output

Location of output for log, result, and error files.

./Remove-VsaStagnantAgent-log.txt