Skip to content

local_user_delete.ps1

Corey Watson edited this page Dec 19, 2025 · 1 revision

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

  1. Hardcoded values (username)
  2. 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

  1. If "listusers" mode: lists all local users and exits
  2. Validates user exists
  3. Removes user profile (CIM then filesystem fallback)
  4. Removes local user account
  5. 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

Clone this wiki locally