local_user_delete.ps1 - limehawk/rmm-scripts GitHub Wiki
local_user_delete.ps1
Deletes a local user account and its associated profile directory.
Overview
This script deletes a local user account and its associated profile directory. Completely removes the user from the system including their files.
Purpose
Deletes a local user account and its associated profile directory. Completely removes the user from the system including their files.
Prerequisites
- Windows 10/11
- Admin privileges required
- PowerShell 5.1+
Configuration
Data Sources & Priority
- Hardcoded values (username)
- WMI/CIM for profile removal
Required Inputs
- UserToDelete : Username of the account to delete Set to "listusers" to only list current users
Settings
- Removes user profile via CIM (preferred method)
- Falls back to direct filesystem removal if CIM fails
- Lists users if no username provided or "listusers" specified
Behavior
- If "listusers" mode: lists all local users and exits
- Validates user exists
- Removes user profile (CIM then filesystem fallback)
- Removes local user account
- Reports final status
Security Notes
- DESTRUCTIVE OPERATION - data cannot be recovered
- No secrets in logs
- Backup important data before running
Exit Codes
- 0: Success
- 1: Failure
Example Output
[ INPUT VALIDATION ]
--------------------------------------------------------------
User to Delete : tempuser
[ OPERATION ]
--------------------------------------------------------------
Found user: tempuser
Removing user profile...
Profile removed via CIM
Removing user account...
User account removed
[ RESULT ]
--------------------------------------------------------------
Status : Success
User : tempuser (deleted)
[ SCRIPT COMPLETED ]
--------------------------------------------------------------
Version History
- 2025-11-29 v1.0.0 Initial Style A implementation
Links
- View Script Source
- Scripts - Back to script index