-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUninstall-Python.ps1
More file actions
29 lines (24 loc) · 1.3 KB
/
Uninstall-Python.ps1
File metadata and controls
29 lines (24 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
[CmdletBinding()]
param (
[Parameter(Mandatory=$false)]
[String] $pythonVersion = "3.13.2"
,
[Parameter(Mandatory=$false)]
[String] $agentToolsDirectory = "C:\Agent\_work\_tool"
)
# Check if the script is running with administrative privileges
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Error "This script needs to be run as an administrator."
exit 1
}
Write-Host "Uninstalling Python $pythonVersion. This may take a while" -ForegroundColor Green
# Uninstall Python from agent tools directory
$uninstallPath = "$agentToolsDirectory\Python\$pythonVersion\x64\python-$pythonVersion-amd64.exe"
if (Test-Path $uninstallPath) {
Start-Process -FilePath $uninstallPath -ArgumentList "/uninstall /quiet" -NoNewWindow -Wait
Remove-Item -Path "$agentToolsDirectory\Python\$pythonVersion\x64" -Recurse -Force
Remove-Item -Path "$agentToolsDirectory\Python\$pythonVersion\" -Recurse -Force
Write-Host "Python $pythonVersion uninstalled successfully from $agentToolsDirectory." -ForegroundColor Green
}
Write-Host "Please manually uninstall Python from system-wide installation via Control Panel." -ForegroundColor Orange
Read-Host "Press any key to exit..."