title: How do I remove Python installations with PowerShell Package Management?
body: <p>I want to write a script which cleans up all existing versions of Python on a machine, and a separate script to re-install both versions 2.7 and 3.5 in standardized locations. I'm currently trying to do this using the Package Management cmdlets in PowerShell 5.1.14393.187.</p>
  
  <p>For the cleanup script, I started with PowerShell's package commands:</p>
  
  <pre><code>Get-Package "*python*" | Uninstall-Package
  </code></pre>
  
  <p>Which, when run from an admin console, seems to work nicely, but on further investigation leaves some packages remaining...   </p>
  
  <pre><code>PS C:\WINDOWS\system32&gt; Get-Package "*python*"
  
  Name                           Version          Source                           ProviderName
  ----                           -------          ------                           ------------
  Python 3.5.1 (64-bit)          3.5.1150.0                                        Programs
  Python 3.5.1 pip Bootstrap ... 3.5.1150.0                                        msi
  Python 3.5.1 Tcl/Tk Support... 3.5.1150.0                                        msi
  Python 2.7.11                  2.7.11150                                         msi
  Python 3.5.2 pip Bootstrap ... 3.5.2150.0                                        msi
  Python 3.5.2 (32-bit)          3.5.2150.0                                        Programs
  </code></pre>
  
  <p><strong>Why are these packages still present after Uninstall-Package? Is there a best-practice way to do this? Is there a best-practice way to script Python's re-installation so this won't happen again?</strong></p>
  
  <p><strong>Update</strong></p>
  
  <p>I've had some success in cleaning up the majority of this by using the control panel GUI to first repair and then uninstall the Python 3 installations.  I'm surprised there is no <code>Repair-Package</code> command to go with <code>Get-Package</code>.   </p>
  
  <p>Once the other parts of Python 3 were repaired, there was one MSI package called "Python Launcher", and the Python 2.7 MSI package remaining reported by <code>Get-Package</code>, but nothing in the GUI.    At this point <code>Uninstall-Package</code> on the "Python Launcher" succeeded with a warning that a reboot was required.  No such luck with msi:Python 2.7.11/2.7.11150.   </p>
  
  <hr>
  
  <p>Additional information:</p>
  
  <p>I think Chocolatey v0.10.1 may have contributed to the current situation.   At least some of the machines may have had python installed using chocolaty from the public repository.   On the same machine above, I've also tried this:</p>
  
  <pre><code>PS C:\WINDOWS\system32&gt; choco uninstall python
  Chocolatey v0.10.1
  Uninstalling the following packages:
  python
  python is not installed. Cannot uninstall a non-existent package.
  
  Chocolatey uninstalled 0/1 packages. 1 packages failed.
   See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
  
  Failures
   - python - python is not installed. Cannot uninstall a non-existent package.
  
  Did you know the proceeds of Pro (and some proceeds from other
   licensed editions) go into bettering the community infrastructure?
   Your support ensures an active community, it makes you look smarter,
   plus it nets you some awesome features!
   https://chocolatey.org/compare
  PS C:\WINDOWS\system32&gt; choco uninstall python3
  Chocolatey v0.10.1
  Uninstalling the following packages:
  python3
  
  python3 v3.5.1
   Skipping auto uninstaller - No registry snapshot.
   python3 has been successfully uninstalled.
  
  Chocolatey uninstalled 1/1 packages. 0 packages failed.
   See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
  
  PS C:\WINDOWS\system32&gt; choco uninstall python2
  Chocolatey v0.10.1
  Uninstalling the following packages:
  python2
  
  python2 v2.7.11
   Running auto uninstaller...
   Skipping auto uninstaller - The application appears to have been uninstalled already by other means.
   python2 has been successfully uninstalled.
  
  Chocolatey uninstalled 1/1 packages. 0 packages failed.
   See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
  
  PS C:\WINDOWS\system32&gt; get-package "*python*"
  
  Name                           Version          Source                           ProviderName
  ----                           -------          ------                           ------------
  Python 3.5.1 (64-bit)          3.5.1150.0                                        Programs
  Python 3.5.1 pip Bootstrap ... 3.5.1150.0                                        msi
  Python 3.5.1 Tcl/Tk Support... 3.5.1150.0                                        msi
  Python 2.7.11                  2.7.11150                                         msi
  Python 3.5.2 pip Bootstrap ... 3.5.2150.0                                        msi
  </code></pre>