Engineering

Command

Rabail Ali Bhatti 2026-09-15
Command

$ProfilesToRemove = Get-CimInstance Win32_UserProfile |

  Where-Object {

    -not $_.Special -and

    -not $_.Loaded -and

    $_.LocalPath -ne 'C:\Users\Administrator'

  }


foreach ($Profile in $ProfilesToRemove) {

  Write-Host "Removing profile: $($Profile.LocalPath) [$($Profile.SID)]" -ForegroundColor Yellow


  try {

    Remove-CimInstance -InputObject $Profile -ErrorAction Stop

    Write-Host "Removed: $($Profile.LocalPath)" -ForegroundColor Green

  }

  catch {

    Write-Warning "FAILED: $($Profile.LocalPath) - $($_.Exception.Message)"

  }

}


Write-Host "`nProfile cleanup complete." -ForegroundColor Cyan


Back to all articles