When a local profile gets deleted, it shows as "Account Unknown" in the list of profiles. For servers where you might have a lot of older profiles (and some organizational turnover), this can mean a lot of wasted space. 

This script performs a SID lookup for each profile in the local computer. If it can't match the SID with a real user, the profile gets whacked.


#Performs a SID lookup for each profile in the local computer. If it can't match the SID with a real 
#user, the profile gets whacked. 
#Needs local admin priv. 
$ALLLocalProfiles = Get-WmiObject -Class Win32_UserProfile 
foreach ($ThisProfile in $ALLLocalProfiles){ 
    $ProfileSID = $ThisProfile.sid 
    $ProfilePath = $ThisProfile.localpath 
        $objUser = ([System.Security.Principal.SecurityIdentifier]($ProfileSID)).translate([System.Security.Principal.NTAccount]).Value 
        Write-host "That worked - $ProfilePath matches to the real user: $objuser " 
        $FoldersizeInBytes = [long](Get-ChildItem -LiteralPath $ProfilePath -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue | Select-Object -Exp Sum) 
        $FolderSizeinMegaBytes = "{0:n2}" -f ($FoldersizeInBytes/1MB) 
        Write-host "The dir $ProfilePath doesn't match to a user, so let us remove its $FolderSizeinMegaBytes MB of cruft"