Created
          October 9, 2025 16:45 
        
      - 
      
- 
        Save langheran/580069af324164f616169e8bc2ae4e82 to your computer and use it in GitHub Desktop. 
    C:\Users\NisimHurst\NDS\scripts\remove_docker_desktop.ps1
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # Run this as Administrator | |
| Write-Host "Stopping Docker processes and services..." | |
| # Stop Docker service if exists | |
| if (Get-Service -Name "com.docker.service" -ErrorAction SilentlyContinue) { | |
| Write-Host "Stopping com.docker.service..." | |
| Stop-Service -Name "com.docker.service" -Force -ErrorAction SilentlyContinue | |
| } | |
| # Kill Docker / Docker Desktop processes | |
| $procs = @("Docker Desktop.exe","docker.exe","com.docker.*") | |
| foreach ($p in $procs) { | |
| Write-Host "Killing process matching $p (if any)..." | |
| Get-Process -Name $p -ErrorAction SilentlyContinue | ForEach-Object { | |
| try { | |
| $_.Kill() | |
| } catch { | |
| # ignore | |
| } | |
| } | |
| } | |
| # If using WSL backend, shut it down | |
| if (Get-Command wsl -ErrorAction SilentlyContinue) { | |
| Write-Host "Shutting down WSL..." | |
| wsl --shutdown | |
| } | |
| Write-Host "Deleting Docker-related directories..." | |
| $dirs = @( | |
| "C:\ProgramData\Docker", | |
| "C:\ProgramData\DockerDesktop", | |
| "C:\Program Files\Docker", | |
| "C:\Users\$env:USERNAME\AppData\Local\Docker", | |
| "C:\Users\$env:USERNAME\AppData\Roaming\Docker", | |
| "C:\Users\$env:USERNAME\AppData\Roaming\Docker Desktop", | |
| "C:\Users\$env:USERNAME\.docker" | |
| ) | |
| foreach ($dir in $dirs) { | |
| if (Test-Path $dir) { | |
| Write-Host "Deleting $dir ..." | |
| try { | |
| Remove-Item -LiteralPath $dir -Recurse -Force -ErrorAction Stop | |
| } catch { | |
| Write-Warning "Failed to delete $dir : $_" | |
| # optionally try to take ownership + reset ACLs then delete | |
| try { | |
| Write-Host "Attempting to take ownership and reset ACLs..." | |
| takeown /F $dir /R /D Y | Out-Null | |
| icacls $dir /reset /T /C | Out-Null | |
| Remove-Item -LiteralPath $dir -Recurse -Force -ErrorAction SilentlyContinue | |
| } catch { | |
| Write-Warning "Also failed after ownership change: $_" | |
| } | |
| } | |
| } else { | |
| Write-Host "Path not found, skipping: $dir" | |
| } | |
| } | |
| Write-Host "Cleanup done. You may reboot to fully clear any locked handles." | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment