Skip to main content

User Management - Purge Local Account and Profile

Summary​

This script can be used to completely remove/purge local accounts (including UserSID) manually and automatically from the agent.

Time Saved by Automation: 5 Minutes

Sample Run​

Sample Run

Dependencies​

Variables​

VariableDescription
psoutThis contains PowerShell script output indicating whether the complete profile was removed or not.
fieldnameThis contains a list of user accounts inactive for 90 days
statusIt detects the dependent monitor status for the agent

Global Parameters​

NameExampleRequiredDescription
LogPathC:/temp/Remove-LocalUserProfile.logTrueThis path stores the logging of the completed script.
AutoPurgeFalseTrueFalse -- Auto Purge is off, Usernames required; True -- Auto Purge is ON, Usernames not required

User Parameters​

NameExampleRequiredDescription
Usernamesuser1,user2,user3True/FalseProvide a list of users to remove when AutoPurge = False; leave blank for AutoPurge = True.

Process​

  • This script can be used to perform both manual removal of users and automatic purge.
  • For automatic purge, set AutoPurge = True; the usernames not logged in for more than 90 days will be picked from the dependent monitor, and this script will trigger as an autofix to remove them.
  • For manual purge, provide the usernames to remove from the agent.

Output​

  • Script log

Changelog​

2025-04-10​

  • Initial version of the document