There are no warranties on this script whatsoever, but here is something you can try:
WARNING!! This will remove Chocolatey and all packages, software, and configurations in the Chocolatey Installation folder from your machine. Everything will be GONE. This is very destructive. DO NOT RUN this script unless you completely understand what the intention of this script is and are good with it. If you mess something up, we cannot help you fix it.
WARNING: Seriously, this script may destroy your machine and require a rebuild. It may have varied results on different machines in the same environment. Think twice before running this.
If you also intend to delete the Chocolatey directory, remove the -WhatIf:
if (!$env:ChocolateyInstall) { Write-Warning "The ChocolateyInstall environment variable was not found. `n Chocolatey is not detected as installed. Nothing to do" return } if (!(Test-Path "$env:ChocolateyInstall")) { Write-Warning "Chocolatey installation not detected at '$env:ChocolateyInstall'. `n Nothing to do." return }
if ($userPath -like "*$env:ChocolateyInstall*") { Write-Output "Chocolatey Install location found in User Path. Removing..." # WARNING: This could cause issues after reboot where nothing is # found if something goes wrong. In that case, look at the backed up # files for PATH. [System.Text.RegularExpressions.Regex]::Replace($userPath, [System.Text.RegularExpressions.Regex]::Escape("$env:ChocolateyInstall\bin") + '(?>;)?', '', [System.Text.RegularExpressions.RegexOptions]::IgnoreCase) | %{[System.Environment]::SetEnvironmentVariable('PATH', $_.Replace(";;",";"), 'User')} }
if ($machinePath -like "*$env:ChocolateyInstall*") { Write-Output "Chocolatey Install location found in Machine Path. Removing..." # WARNING: This could cause issues after reboot where nothing is # found if something goes wrong. In that case, look at the backed up # files for PATH. [System.Text.RegularExpressions.Regex]::Replace($machinePath, [System.Text.RegularExpressions.Regex]::Escape("$env:ChocolateyInstall\bin") + '(?>;)?', '', [System.Text.RegularExpressions.RegexOptions]::IgnoreCase) | %{[System.Environment]::SetEnvironmentVariable('PATH', $_.Replace(";;",";"), 'Machine')} }
# Adapt for any services running in subfolders of ChocolateyInstall $agentService = Get-Service -Name chocolatey-agent -ErrorAction SilentlyContinue if ($agentService -and $agentService.Status -eq 'Running') { $agentService.Stop() } # TODO: add other services here
# delete the contents (remove -WhatIf to actually remove) Remove-Item -Recurse -Force "$env:ChocolateyInstall" -WhatIf