Untitled

mail@pastecode.io avatar
unknown
plain_text
25 days ago
624 B
2
Indexable
Never
# Get all user profiles excluding system profiles (Default, Public, and All Users)
$profiles = Get-WmiObject Win32_UserProfile | Where-Object {
    $_.Special -eq $false -and $_.LocalPath -notlike "*\Administrator" -and $_.LocalPath -notlike "*\Default*"
}

foreach ($profile in $profiles) {
    try {
        # Remove the user profile folder and registry entry
        Write-Host "Deleting profile: $($profile.LocalPath)"
        $profile.Delete()
        Write-Host "Profile deleted successfully: $($profile.LocalPath)"
    } catch {
        Write-Host "Failed to delete profile: $($profile.LocalPath). Error: $_"
    }
}
Leave a Comment