ACCOUNT UNKNOWN User Profiles are most likely just chewing up disk space on your computer. They are the profiles from users that have been deleted in Active Directory or on your local computer. If you run an RDS server or have had alot of administrators, you can have a lot of dead profiles on your Windows Server, that you should probably get rid of.

In this PowerShell Script, we will delete only the account profiles that are unknown. This will help to keep your system clean and free from old account profiles that you may no longer be using.

HERE is the .PS1 to delete the user accounts and here it is in text form:

# By Khalid Abullahi URTech.ca
# Get a list of all user profiles on the computer
$userProfiles = Get-WmiObject -Class Win32_UserProfile

foreach ($profile in $userProfiles) {
    $userSID = $profile.SID
    $userAccount = $null

    # Try to get the user account associated with the profile
    try {
        $userAccount = [System.Security.Principal.SecurityIdentifier]::new($userSID).Translate([System.Security.Principal.NTAccount]).Value
    } catch {
        # An exception occurs when the user account doesn't exist
    }

    # Check if a user account was found
    if ($userAccount -eq $null) {
        # Delete the user profile
        Write-Host "Deleting user profile with SID $userSID"
        Remove-WmiObject -InputObject $profile
    }
}

Write-Host "User profiles cleanup completed."

This script can be used to delete user accounts that are no longer active, old user profiles that have been abandoned by the user, or profiles that are flagged as dead accounts. By using this simple PowerShell Script, you can quickly and easily remove unwanted user profiles from your system!


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *