Whenever a user logs on to your computer, a user profile is created, and in the previous tip we explained how PowerShell can dump a list of user profiles found on a computer.

If you’d like to get rid of a user account, PowerShell can wipe it for you. Here is how:

First, adjust the $domain and $username variables to point to the user profile that you would like to delete. Next, run the code below in a PowerShell with full Administrator privileges:

#requires -RunAsAdministrator

$domain = 'ccie'
$username = 'user01'

# get user SID
$sid = (New-Object Security.Principal.NTAccount($domain, $username)).Translate([Security.Principal.SecurityIdentifier]).Value

Get-WmiObject -ClassName Win32_UserProfile -Filter "SID='$sid'" |
  ForEach-Object { 

The first part translates the username into a SID that is then used to identify the user profile. The WMI Delete() method deletes the entire user profile. Warning: you will lose all data in the profile you delete.

Twitter This Tip! ReTweet this Tip!