How to delete user profiles on Windows
unknown
plain_text
a year ago
624 B
12
Indexable
# 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: $_"
}
}
Editor is loading...
Leave a Comment