Choco uninstall
Jump to navigation
Jump to search
Choco Uninstall
# Ensure the script is running as administrator if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Write-Host "Please run this script as an administrator." exit } # Stop Chocolatey processes (if any) Write-Host "Stopping Chocolatey processes..." Stop-Process -Name "choco*" -Force -ErrorAction SilentlyContinue # Remove Chocolatey installation directory Write-Host "Removing Chocolatey installation directory..." Remove-Item -Recurse -Force "C:\ProgramData\chocolatey" # Remove Chocolatey environment variables Write-Host "Removing Chocolatey environment variables..." [System.Environment]::SetEnvironmentVariable("ChocolateyInstall", $null, [System.EnvironmentVariableTarget]::Machine) [System.Environment]::SetEnvironmentVariable("ChocolateyLastPathUpdate", $null, [System.EnvironmentVariableTarget]::Machine) # Remove Chocolatey from the PATH environment variable Write-Host "Removing Chocolatey from the PATH environment variable..." $envPath = [System.Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine) $envPath = $envPath -replace ";C:\\ProgramData\\chocolatey\\bin", "" [System.Environment]::SetEnvironmentVariable("Path", $envPath, [System.EnvironmentVariableTarget]::Machine) rm -r 'C:\ProgramData\ChocolateyHttpCache\' Write-Host "Chocolatey has been uninstalled successfully."