Python 3.10 Install and Uninstall (PSADT v4)

This article will serve as an informative guide and give you a clear understanding of how to perform silent or interactive installs and uninstalls of Python 3.10 using the PowerShell App Deployment Toolkit v4. The PowerShell App Deployment Toolkit (PSADT) is a collection of PowerShell scripts and functions designed to simplify the deployment of software applications. It helps IT administrators automate tasks such as installing, configuring, and uninstalling applications, and it is commonly used for software packaging and deployment within enterprise environments. PSADT can be used in conjunction with tools like Microsoft Endpoint Configuration Manager (formerly SCCM), Intune, or other deployment systems.

How to Install Python 3.10 Using the PowerShell App Deployment Toolkit v4

  • Open Windows PowerShell by Right-Clicking on Windows PowerShell and selecting Run as Administrator
  • Enter the following commands:
Set-ExecutionPolicy Bypass -Scope CurrentUser
Install-Module -Name PSAppDeployToolkit -Scope CurrentUser
Import-Module PSAppDeployToolkit
New-ADTTemplate -Destination 'C:\Temp' -Name 'Python310' -Show
  • Navigate to: https://www.python.org/ftp/python/
  • Download & Copy the python-3.10.x.exe to “C:\Temp\Python310\Files\”
  • Download & Copy the python-3.10.x-amd64.exe to “C:\Temp\Python310\Files\”
  • Open Notepad or your favorite text editor
  • Add the following lines and set values based on your preferences:
<Options>
  <Option Name="InstallAllUsers" Value="1" />
  <Option Name="TargetDir" Value="C:\Python310" />
  <Option Name="DefaultAllUsersTargetDir" Value="C:\Python310" />
  <Option Name="DefaultJustForMeTargetDir" Value="C:\Python310" />
  <Option Name="DefaultCustomTargetDir" Value="C:\Python310" />
  <Option Name="AssociateFiles" Value="1" />
  <Option Name="CompileAll" Value="1" />
  <Option Name="PrependPath" Value="1" />
  <Option Name="AppendPath" Value="0" />
  <Option Name="Shortcuts" Value="1" />
  <Option Name="Include_doc" Value="1" />
  <Option Name="Include_debug" Value="1" />
  <Option Name="Include_dev" Value="1" />
  <Option Name="Include_exe" Value="1" />
  <Option Name="Include_launcher" Value="1" />
  <Option Name="InstallLauncherAllUsers" Value="1" />
  <Option Name="Include_lib" Value="1" />
  <Option Name="Include_pip" Value="1" />
  <Option Name="Include_symbols" Value="1" />
  <Option Name="Include_tcltk" Value="1" />
  <Option Name="Include_test" Value="1" />
  <Option Name="Include_tools" Value="1" />
  <Option Name="LauncherOnly" Value="0" />
  <Option Name="SimpleInstall" Value="0" />
  <Option Name="SimpleInstallDescription"></Option>
</Options>
  • Save the file to “C:\Temp\Python310\Files\” and name it: unattend.xml
  • Replace the default Invoke-AppDeployToolkit.ps1 template with the script below
<#

.SYNOPSIS
PSAppDeployToolkit - This script performs the installation or uninstallation of Python 3.10.

.DESCRIPTION
- The script is provided as a template to perform an install, uninstall, or repair of an application(s).
- The script either performs an "Install", "Uninstall", or "Repair" deployment type.
- The install deployment type is broken down into 3 main sections/phases: Pre-Install, Install, and Post-Install.

The script imports the PSAppDeployToolkit module which contains the logic and functions required to install or uninstall an application.

.PARAMETER DeploymentType
The type of deployment to perform.

.PARAMETER DeployMode
Specifies whether the installation should be run in Interactive (shows dialogs), Silent (no dialogs), NonInteractive (dialogs without prompts) mode, or Auto (shows dialogs if a user is logged on, device is not in the OOBE, and there's no running apps to close).

Silent mode is automatically set if it is detected that the process is not user interactive, no users are logged on, the device is in Autopilot mode, or there's specified processes to close that are currently running.

.PARAMETER SuppressRebootPassThru
Suppresses the 3010 return code (requires restart) from being passed back to the parent process (e.g. SCCM) if detected from an installation. If 3010 is passed back to SCCM, a reboot prompt will be triggered.

.PARAMETER TerminalServerMode
Changes to "user install mode" and back to "user execute mode" for installing/uninstalling applications for Remote Desktop Session Hosts/Citrix servers.

.PARAMETER DisableLogging
Disables logging to file for the script.

.EXAMPLE
powershell.exe -File Invoke-AppDeployToolkit.ps1

.EXAMPLE
powershell.exe -File Invoke-AppDeployToolkit.ps1 -DeployMode Silent

.EXAMPLE
powershell.exe -File Invoke-AppDeployToolkit.ps1 -DeploymentType Uninstall

.EXAMPLE
Invoke-AppDeployToolkit.exe -DeploymentType Install -DeployMode Silent

.INPUTS
None. You cannot pipe objects to this script.

.OUTPUTS
None. This script does not generate any output.

.NOTES
Toolkit Exit Code Ranges:
- 60000 - 68999: Reserved for built-in exit codes in Invoke-AppDeployToolkit.ps1, and Invoke-AppDeployToolkit.exe
- 69000 - 69999: Recommended for user customized exit codes in Invoke-AppDeployToolkit.ps1
- 70000 - 79999: Recommended for user customized exit codes in PSAppDeployToolkit.Extensions module.

.LINK
https://psappdeploytoolkit.com

#>

[CmdletBinding()]
param
(
    # Default is 'Install'.
    [Parameter(Mandatory = $false)]
    [ValidateSet('Install', 'Uninstall', 'Repair')]
    [System.String]$DeploymentType,

    # Default is 'Auto'. Don't hard-code this unless required.
    [Parameter(Mandatory = $false)]
    [ValidateSet('Auto', 'Interactive', 'NonInteractive', 'Silent')]
    [System.String]$DeployMode,

    [Parameter(Mandatory = $false)]
    [System.Management.Automation.SwitchParameter]$SuppressRebootPassThru,

    [Parameter(Mandatory = $false)]
    [System.Management.Automation.SwitchParameter]$TerminalServerMode,

    [Parameter(Mandatory = $false)]
    [System.Management.Automation.SwitchParameter]$DisableLogging
)


##================================================
## MARK: Variables
##================================================

# Zero-Config MSI support is provided when "AppName" is null or empty.
# By setting the "AppName" property, Zero-Config MSI will be disabled.
$adtSession = @{
    # App variables.
    AppVendor = 'Python Software Foundation'
    AppName = 'Python 3.10'
    AppVersion = ''
    AppArch = ''
    AppLang = 'EN'
    AppRevision = '01'
    AppSuccessExitCodes = @(0)
    AppRebootExitCodes = @(1641, 3010)
    AppProcessesToClose = @(@{ Name = 'python'; Description = 'Python' })
    AppScriptVersion = '1.0.0'
    AppScriptDate = '2025-09-18'
    AppScriptAuthor = 'Jason Bergner'
    RequireAdmin = $true

    # Install Titles (Only set here to override defaults set by the toolkit).
    InstallName = ''
    InstallTitle = ''

    # Script variables.
    DeployAppScriptFriendlyName = $MyInvocation.MyCommand.Name
    DeployAppScriptParameters = $PSBoundParameters
    DeployAppScriptVersion = '4.1.3'
}

function Install-ADTDeployment
{
    [CmdletBinding()]
    param
    (
    )

    ##================================================
    ## MARK: Pre-Install
    ##================================================
    $adtSession.InstallPhase = "Pre-$($adtSession.DeploymentType)"

    ## Microsoft Intune Win32 App Workaround - Check If Running 32-bit PowerShell on 64-bit OS, Restart as 64-bit Process
    if (!([Environment]::Is64BitProcess)) {
        if([Environment]::Is64BitOperatingSystem) {
            
            Write-ADTLogEntry -Message "Running 32-bit PowerShell on 64-bit OS, Restarting as 64-bit Process..." -Severity 1
            
            $arguments = "-NoProfile -ExecutionPolicy ByPass -WindowStyle Hidden -File `"" + $myinvocation.mycommand.definition + "`""
            $path = (Join-Path $Env:SystemRoot -ChildPath "\sysnative\WindowsPowerShell\v1.0\powershell.exe")

            Start-Process $path -ArgumentList $arguments -Wait
            
            Write-ADTLogEntry -Message "Finished Running x64 version of PowerShell" -Severity 1
            Exit
        }
        else {
            Write-ADTLogEntry -Message "Running 32-bit PowerShell on 32-bit OS" -Severity 1
        }
    }

    ## Show Welcome Message, close processes with a 60 second countdown before automatically closing. 
    ## Switch to $true to allow up to 3 deferrals, verify there is enough disk space to complete the install, and persist the prompt.
    $saiwParams = @{
        CloseProcessesCountdown = 60
        AllowDefer = $false
        DeferTimes = 3
        CheckDiskSpace = $false
        PersistPrompt = $false
    }
    if ($adtSession.AppProcessesToClose.Count -gt 0)
    {
        $saiwParams.Add('CloseProcesses', $adtSession.AppProcessesToClose)
    }
    Show-ADTInstallationWelcome @saiwParams

    ## Show Progress Message (with a message to indicate the application is being uninstalled).
    Show-ADTInstallationProgress -StatusMessage "Removing Any Existing Version of $($adtSession.AppName). Please Wait..."

    ## Remove Any Existing Version of Python 3.10
    function Uninstall-PythonComponent {
        param (
            [string]$RegexPattern,
            [string]$ComponentName
        )

        ## System uninstall for Python 3.10 components
        Uninstall-ADTApplication -FilterScript { $_.DisplayName -match $RegexPattern } -ApplicationType 'MSI' -IgnoreExitCodes '1605'

        ## User-based uninstall for Python 3.10 components
        $appName = Get-ADTApplication -FilterScript { $_.DisplayName -match $RegexPattern }

        if ($appName) {
            foreach ($app in $appName) {
                $guid = $app.UninstallString -replace 'MsiExec.exe /[IX]', ''
                [string]$exeMsiexec = "$envSystem32Directory\msiexec.exe"

                Start-ADTProcessAsUser -FilePath $exeMsiexec -ArgumentList "/x $guid REBOOT=ReallySuppress /qn"
                Start-Sleep -Seconds 5
            }
        } else {
            Write-ADTLogEntry -Message "$($adtSession.AppName) $ComponentName is not currently installed." -Severity 1
        }
    }

    $pythonComponents = @(
        @{ Pattern = '^Python 3\.10.*Add to Path'; Component = 'Add to Path' },
        @{ Pattern = '^Python 3\.10.*pip Bootstrap'; Component = 'pip Bootstrap' },
        @{ Pattern = '^Python 3\.10.*Tcl/Tk Support \(32-bit debug\)'; Component = 'Tcl/Tk Support (32-bit debug)' },
        @{ Pattern = '^Python 3\.10.*Tcl/Tk Support \(64-bit debug\)'; Component = 'Tcl/Tk Support (64-bit debug)' },
        @{ Pattern = '^Python 3\.10.*Tcl/Tk Support \(32-bit symbols\)'; Component = 'Tcl/Tk Support (32-bit symbols)' },
        @{ Pattern = '^Python 3\.10.*Tcl/Tk Support \(64-bit symbols\)'; Component = 'Tcl/Tk Support (64-bit symbols)' },
        @{ Pattern = '^Python 3\.10.*Tcl/Tk Support \(32-bit\)'; Component = 'Tcl/Tk Support (32-bit)' },
        @{ Pattern = '^Python 3\.10.*Tcl/Tk Support \(64-bit\)'; Component = 'Tcl/Tk Support (64-bit)' },
        @{ Pattern = '^Python 3\.10.*Utility Scripts'; Component = 'Utility Scripts' },
        @{ Pattern = '^Python 3\.10.*Documentation'; Component = 'Documentation' },
        @{ Pattern = '^Python 3\.10.*Test Suite \(32-bit debug\)'; Component = 'Test Suite (32-bit debug)' },
        @{ Pattern = '^Python 3\.10.*Test Suite \(64-bit debug\)'; Component = 'Test Suite (64-bit debug)' },
        @{ Pattern = '^Python 3\.10.*Test Suite \(32-bit symbols\)'; Component = 'Test Suite (32-bit symbols)' },
        @{ Pattern = '^Python 3\.10.*Test Suite \(64-bit symbols\)'; Component = 'Test Suite (64-bit symbols)' },
        @{ Pattern = '^Python 3\.10.*Test Suite \(32-bit\)'; Component = 'Test Suite (32-bit)' },
        @{ Pattern = '^Python 3\.10.*Test Suite \(64-bit\)'; Component = 'Test Suite (64-bit)' },
        @{ Pattern = '^Python 3\.10.*Standard Library \(32-bit debug\)'; Component = 'Standard Library (32-bit debug)' },
        @{ Pattern = '^Python 3\.10.*Standard Library \(64-bit debug\)'; Component = 'Standard Library (64-bit debug)' },
        @{ Pattern = '^Python 3\.10.*Standard Library \(32-bit symbols\)'; Component = 'Standard Library (32-bit symbols)' },
        @{ Pattern = '^Python 3\.10.*Standard Library \(64-bit symbols\)'; Component = 'Standard Library (64-bit symbols)' },
        @{ Pattern = '^Python 3\.10.*Standard Library \(32-bit\)'; Component = 'Standard Library (32-bit)' },
        @{ Pattern = '^Python 3\.10.*Standard Library \(64-bit\)'; Component = 'Standard Library (64-bit)' },
        @{ Pattern = '^Python 3\.10.*Development Libraries \(32-bit debug\)'; Component = 'Development Libraries (32-bit debug)' },
        @{ Pattern = '^Python 3\.10.*Development Libraries \(64-bit debug\)'; Component = 'Development Libraries (64-bit debug)' },
        @{ Pattern = '^Python 3\.10.*Development Libraries \(32-bit\)'; Component = 'Development Libraries (32-bit)' },
        @{ Pattern = '^Python 3\.10.*Development Libraries \(64-bit\)'; Component = 'Development Libraries (64-bit)' },
        @{ Pattern = '^Python 3\.10.*Executables \(32-bit debug\)'; Component = 'Executables (32-bit debug)' },
        @{ Pattern = '^Python 3\.10.*Executables \(64-bit debug\)'; Component = 'Executables (64-bit debug)' },
        @{ Pattern = '^Python 3\.10.*Executables \(32-bit symbols\)'; Component = 'Executables (32-bit symbols)' },
        @{ Pattern = '^Python 3\.10.*Executables \(64-bit symbols\)'; Component = 'Executables (64-bit symbols)' },
        @{ Pattern = '^Python 3\.10.*Executables \(32-bit\)'; Component = 'Executables (32-bit)' },
        @{ Pattern = '^Python 3\.10.*Executables \(64-bit\)'; Component = 'Executables (64-bit)' },
        @{ Pattern = '^Python 3\.10.*Core Interpreter \(32-bit debug\)'; Component = 'Core Interpreter (32-bit debug)' },
        @{ Pattern = '^Python 3\.10.*Core Interpreter \(64-bit debug\)'; Component = 'Core Interpreter (64-bit debug)' },
        @{ Pattern = '^Python 3\.10.*Core Interpreter \(32-bit symbols\)'; Component = 'Core Interpreter (32-bit symbols)' },
        @{ Pattern = '^Python 3\.10.*Core Interpreter \(64-bit symbols\)'; Component = 'Core Interpreter (64-bit symbols)' },
        @{ Pattern = '^Python 3\.10.*Core Interpreter \(32-bit\)'; Component = 'Core Interpreter (32-bit)' },
        @{ Pattern = '^Python 3\.10.*Core Interpreter \(64-bit\)'; Component = 'Core Interpreter (64-bit)' },
        @{ Pattern = '^Python Launcher'; Component = 'Python Launcher' }
    )

    foreach ($component in $pythonComponents) {
        Uninstall-PythonComponent -RegexPattern $component.Pattern -ComponentName $component.Component
    }

    ## Remove Any Existing Versions of Python 3.10 (User Profile)
    [string[]]$profilePaths = Get-ADTUserProfiles | Select-Object -ExpandProperty ProfilePath

    foreach ($profile in $profilePaths) {
        $packageCache = Join-Path -Path $profile -ChildPath "AppData\Local\Package Cache"
        
        if (Test-Path -Path $packageCache) {
            $pythonInstallers = Get-ChildItem -Path $packageCache -Include "python-3.10*.exe" -Recurse -ErrorAction SilentlyContinue

            foreach ($installer in $pythonInstallers) {
                try {
                    Write-ADTLogEntry -Message "Found installer: $($installer.FullName). Attempting to uninstall $($adtSession.AppName)..." -Severity 1                   
                    Start-ADTProcessAsUser -FilePath $installer.FullName -ArgumentList '/uninstall /quiet /norestart' -WaitForChildProcesses
                }
                catch {
                    Write-ADTLogEntry -Message "Failed to uninstall using $($installer.FullName). Error: $_" -Severity 2
                }
            }
        }
        else {
            Write-ADTLogEntry -Message "$($adtSession.AppName) Package Cache not found for profile: $profile" -Severity 1
        }
    }     

    ##================================================
    ## MARK: Install
    ##================================================
    $adtSession.InstallPhase = $adtSession.DeploymentType

    ## Perform Python 3.10 Installation
    $files = Get-ChildItem -Path "$($adtSession.DirFiles)" -File -Recurse -ErrorAction SilentlyContinue

    if ($ENV:PROCESSOR_ARCHITECTURE -eq 'x86') {
        Write-ADTLogEntry -Message "Detected 32-bit OS Architecture" -Severity 1

        $xmlPath   = $files | Where-Object { $_.Name -match 'unattend.xml' }
        $exePath32 = $files | Where-Object { $_.Name -match '^python-3\.10\.\d+\.exe$' }

        ## Install Python 3.10 on 32-bit OS
        if ($exePath32.Count -gt 0 -and $xmlPath.Count -gt 0) {
            Show-ADTInstallationProgress -StatusMessage "Installing $($adtSession.AppName) 32-bit. Please Wait..."
            Start-ADTProcess -FilePath "$($exePath32.FullName)" -ArgumentList "/quiet `"$($xmlPath.FullName)`"" -WindowStyle 'Hidden'
        }
        else {
            Write-ADTLogEntry -Message "$($adtSession.AppName) installer and/or unattend.xml were not found. Installation aborted." -Severity 2
            Show-ADTInstallationPrompt -Message "$($adtSession.AppName) installer and/or unattend.xml were not found. Installation aborted." -ButtonRightText 'OK'
        }
    }
    else {
        Write-ADTLogEntry -Message "Detected 64-bit OS Architecture" -Severity 1

        $xmlPath   = $files | Where-Object { $_.Name -match 'unattend.xml' }
        $exePath32 = $files | Where-Object { $_.Name -match '^python-3\.10\.\d+\.exe$' }
        $exePath64 = $files | Where-Object { $_.Name -match '^python-3\.10\.\d+-(amd64|arm64)\.exe$' }

        ## Install Python 3.10 64-bit on 64-bit OS
        if ($exePath64.Count -gt 0 -and $xmlPath.Count -gt 0) {
            Show-ADTInstallationProgress -StatusMessage "Installing $($adtSession.AppName) 64-bit. Please Wait..."
            Start-ADTProcess -FilePath "$($exePath64.FullName)" -ArgumentList "/quiet `"$($xmlPath.FullName)`"" -WindowStyle 'Hidden'
        }
        ## Install Python 3.10 32-bit on 64-bit OS
        elseif ($exePath32.Count -gt 0 -and $xmlPath.Count -gt 0) {
            Show-ADTInstallationProgress -StatusMessage "Installing $($adtSession.AppName) 32-bit. Please Wait..."
            Start-ADTProcess -FilePath "$($exePath32.FullName)" -ArgumentList "/quiet `"$($xmlPath.FullName)`"" -WindowStyle 'Hidden'
        }
        else {
            Write-ADTLogEntry -Message "$($adtSession.AppName) installer and/or unattend.xml were not found. Installation aborted." -Severity 2
            Show-ADTInstallationPrompt -Message "$($adtSession.AppName) installer and/or unattend.xml were not found. Installation aborted." -ButtonRightText 'OK'
        }
    }

    ##================================================
    ## MARK: Post-Install
    ##================================================
    $adtSession.InstallPhase = "Post-$($adtSession.DeploymentType)"

}

function Uninstall-ADTDeployment
{
    [CmdletBinding()]
    param
    (
    )

    ##================================================
    ## MARK: Pre-Uninstall
    ##================================================
    $adtSession.InstallPhase = "Pre-$($adtSession.DeploymentType)"

    ## If there are processes to close, show Welcome Message with a 60 second countdown before automatically closing.
    if ($adtSession.AppProcessesToClose.Count -gt 0)
    {
        Show-ADTInstallationWelcome -CloseProcesses $adtSession.AppProcessesToClose -CloseProcessesCountdown 60
    }

    ## Show Progress Message (with a message to indicate the application is being uninstalled).
    Show-ADTInstallationProgress -StatusMessage "Uninstalling Any Existing Version of $($adtSession.AppName). Please Wait..."

    ##================================================
    ## MARK: Uninstall
    ##================================================
    $adtSession.InstallPhase = $adtSession.DeploymentType

    ## Uninstall Any Existing Version of Python 3.10
    function Uninstall-PythonComponent {
        param (
            [string]$RegexPattern,
            [string]$ComponentName
        )

        ## System uninstall for Python 3.10 components
        Uninstall-ADTApplication -FilterScript { $_.DisplayName -match $RegexPattern } -ApplicationType 'MSI' -IgnoreExitCodes '1605'

        ## User-based uninstall for Python 3.10 components
        $appName = Get-ADTApplication -FilterScript { $_.DisplayName -match $RegexPattern }

        if ($appName) {
            foreach ($app in $appName) {
                $guid = $app.UninstallString -replace 'MsiExec.exe /[IX]', ''
                [string]$exeMsiexec = "$envSystem32Directory\msiexec.exe"

                Start-ADTProcessAsUser -FilePath $exeMsiexec -ArgumentList "/x $guid REBOOT=ReallySuppress /qn"
                Start-Sleep -Seconds 5
            }
        } else {
            Write-ADTLogEntry -Message "$($adtSession.AppName) $ComponentName is not currently installed." -Severity 1
        }
    }

    $pythonComponents = @(
        @{ Pattern = '^Python 3\.10.*Add to Path'; Component = 'Add to Path' },
        @{ Pattern = '^Python 3\.10.*pip Bootstrap'; Component = 'pip Bootstrap' },
        @{ Pattern = '^Python 3\.10.*Tcl/Tk Support \(32-bit debug\)'; Component = 'Tcl/Tk Support (32-bit debug)' },
        @{ Pattern = '^Python 3\.10.*Tcl/Tk Support \(64-bit debug\)'; Component = 'Tcl/Tk Support (64-bit debug)' },
        @{ Pattern = '^Python 3\.10.*Tcl/Tk Support \(32-bit symbols\)'; Component = 'Tcl/Tk Support (32-bit symbols)' },
        @{ Pattern = '^Python 3\.10.*Tcl/Tk Support \(64-bit symbols\)'; Component = 'Tcl/Tk Support (64-bit symbols)' },
        @{ Pattern = '^Python 3\.10.*Tcl/Tk Support \(32-bit\)'; Component = 'Tcl/Tk Support (32-bit)' },
        @{ Pattern = '^Python 3\.10.*Tcl/Tk Support \(64-bit\)'; Component = 'Tcl/Tk Support (64-bit)' },
        @{ Pattern = '^Python 3\.10.*Utility Scripts'; Component = 'Utility Scripts' },
        @{ Pattern = '^Python 3\.10.*Documentation'; Component = 'Documentation' },
        @{ Pattern = '^Python 3\.10.*Test Suite \(32-bit debug\)'; Component = 'Test Suite (32-bit debug)' },
        @{ Pattern = '^Python 3\.10.*Test Suite \(64-bit debug\)'; Component = 'Test Suite (64-bit debug)' },
        @{ Pattern = '^Python 3\.10.*Test Suite \(32-bit symbols\)'; Component = 'Test Suite (32-bit symbols)' },
        @{ Pattern = '^Python 3\.10.*Test Suite \(64-bit symbols\)'; Component = 'Test Suite (64-bit symbols)' },
        @{ Pattern = '^Python 3\.10.*Test Suite \(32-bit\)'; Component = 'Test Suite (32-bit)' },
        @{ Pattern = '^Python 3\.10.*Test Suite \(64-bit\)'; Component = 'Test Suite (64-bit)' },
        @{ Pattern = '^Python 3\.10.*Standard Library \(32-bit debug\)'; Component = 'Standard Library (32-bit debug)' },
        @{ Pattern = '^Python 3\.10.*Standard Library \(64-bit debug\)'; Component = 'Standard Library (64-bit debug)' },
        @{ Pattern = '^Python 3\.10.*Standard Library \(32-bit symbols\)'; Component = 'Standard Library (32-bit symbols)' },
        @{ Pattern = '^Python 3\.10.*Standard Library \(64-bit symbols\)'; Component = 'Standard Library (64-bit symbols)' },
        @{ Pattern = '^Python 3\.10.*Standard Library \(32-bit\)'; Component = 'Standard Library (32-bit)' },
        @{ Pattern = '^Python 3\.10.*Standard Library \(64-bit\)'; Component = 'Standard Library (64-bit)' },
        @{ Pattern = '^Python 3\.10.*Development Libraries \(32-bit debug\)'; Component = 'Development Libraries (32-bit debug)' },
        @{ Pattern = '^Python 3\.10.*Development Libraries \(64-bit debug\)'; Component = 'Development Libraries (64-bit debug)' },
        @{ Pattern = '^Python 3\.10.*Development Libraries \(32-bit\)'; Component = 'Development Libraries (32-bit)' },
        @{ Pattern = '^Python 3\.10.*Development Libraries \(64-bit\)'; Component = 'Development Libraries (64-bit)' },
        @{ Pattern = '^Python 3\.10.*Executables \(32-bit debug\)'; Component = 'Executables (32-bit debug)' },
        @{ Pattern = '^Python 3\.10.*Executables \(64-bit debug\)'; Component = 'Executables (64-bit debug)' },
        @{ Pattern = '^Python 3\.10.*Executables \(32-bit symbols\)'; Component = 'Executables (32-bit symbols)' },
        @{ Pattern = '^Python 3\.10.*Executables \(64-bit symbols\)'; Component = 'Executables (64-bit symbols)' },
        @{ Pattern = '^Python 3\.10.*Executables \(32-bit\)'; Component = 'Executables (32-bit)' },
        @{ Pattern = '^Python 3\.10.*Executables \(64-bit\)'; Component = 'Executables (64-bit)' },
        @{ Pattern = '^Python 3\.10.*Core Interpreter \(32-bit debug\)'; Component = 'Core Interpreter (32-bit debug)' },
        @{ Pattern = '^Python 3\.10.*Core Interpreter \(64-bit debug\)'; Component = 'Core Interpreter (64-bit debug)' },
        @{ Pattern = '^Python 3\.10.*Core Interpreter \(32-bit symbols\)'; Component = 'Core Interpreter (32-bit symbols)' },
        @{ Pattern = '^Python 3\.10.*Core Interpreter \(64-bit symbols\)'; Component = 'Core Interpreter (64-bit symbols)' },
        @{ Pattern = '^Python 3\.10.*Core Interpreter \(32-bit\)'; Component = 'Core Interpreter (32-bit)' },
        @{ Pattern = '^Python 3\.10.*Core Interpreter \(64-bit\)'; Component = 'Core Interpreter (64-bit)' },
        @{ Pattern = '^Python Launcher'; Component = 'Python Launcher' }
    )

    foreach ($component in $pythonComponents) {
        Uninstall-PythonComponent -RegexPattern $component.Pattern -ComponentName $component.Component
    }

    ## Uninstall Any Existing Versions of Python 3.10 (User Profile)
    [string[]]$profilePaths = Get-ADTUserProfiles | Select-Object -ExpandProperty ProfilePath

    foreach ($profile in $profilePaths) {
        $packageCache = Join-Path -Path $profile -ChildPath "AppData\Local\Package Cache"
        
        if (Test-Path -Path $packageCache) {
            $pythonInstallers = Get-ChildItem -Path $packageCache -Include "python-3.10*.exe" -Recurse -ErrorAction SilentlyContinue

            foreach ($installer in $pythonInstallers) {
                try {
                    Write-ADTLogEntry -Message "Found installer: $($installer.FullName). Attempting to uninstall $($adtSession.AppName)..." -Severity 1                   
                    Start-ADTProcessAsUser -FilePath $installer.FullName -ArgumentList '/uninstall /quiet /norestart' -WaitForChildProcesses
                }
                catch {
                    Write-ADTLogEntry -Message "Failed to uninstall using $($installer.FullName). Error: $_" -Severity 2
                }
            }
        }
        else {
            Write-ADTLogEntry -Message "$($adtSession.AppName) Package Cache not found for profile: $profile" -Severity 1
        }
    }  

    ##================================================
    ## MARK: Post-Uninstallation
    ##================================================
    $adtSession.InstallPhase = "Post-$($adtSession.DeploymentType)"

}

function Repair-ADTDeployment
{
    [CmdletBinding()]
    param
    (
    )

    ##================================================
    ## MARK: Pre-Repair
    ##================================================
    $adtSession.InstallPhase = "Pre-$($adtSession.DeploymentType)"

    ##================================================
    ## MARK: Repair
    ##================================================
    $adtSession.InstallPhase = $adtSession.DeploymentType

    ##================================================
    ## MARK: Post-Repair
    ##================================================
    $adtSession.InstallPhase = "Post-$($adtSession.DeploymentType)"

}


##================================================
## MARK: Initialization
##================================================

# Set strict error handling across entire operation.
$ErrorActionPreference = [System.Management.Automation.ActionPreference]::Stop
$ProgressPreference = [System.Management.Automation.ActionPreference]::SilentlyContinue
Set-StrictMode -Version 1

# Import the module and instantiate a new session.
try
{
    # Import the module locally if available, otherwise try to find it from PSModulePath.
    if (Test-Path -LiteralPath "$PSScriptRoot\PSAppDeployToolkit\PSAppDeployToolkit.psd1" -PathType Leaf)
    {
        Get-ChildItem -LiteralPath "$PSScriptRoot\PSAppDeployToolkit" -Recurse -File | Unblock-File -ErrorAction Ignore
        Import-Module -FullyQualifiedName @{ ModuleName = "$PSScriptRoot\PSAppDeployToolkit\PSAppDeployToolkit.psd1"; Guid = '8c3c366b-8606-4576-9f2d-4051144f7ca2'; ModuleVersion = '4.1.3' } -Force
    }
    else
    {
        Import-Module -FullyQualifiedName @{ ModuleName = 'PSAppDeployToolkit'; Guid = '8c3c366b-8606-4576-9f2d-4051144f7ca2'; ModuleVersion = '4.1.3' } -Force
    }

    # Open a new deployment session, replacing $adtSession with a DeploymentSession.
    $iadtParams = Get-ADTBoundParametersAndDefaultValues -Invocation $MyInvocation
    $adtSession = Remove-ADTHashtableNullOrEmptyValues -Hashtable $adtSession
    $adtSession = Open-ADTSession @adtSession @iadtParams -PassThru
}
catch
{
    $Host.UI.WriteErrorLine((Out-String -InputObject $_ -Width ([System.Int32]::MaxValue)))
    exit 60008
}


##================================================
## MARK: Invocation
##================================================

# Commence the actual deployment operation.
try
{
    # Import any found extensions before proceeding with the deployment.
    Get-ChildItem -LiteralPath $PSScriptRoot -Directory | & {
        process
        {
            if ($_.Name -match 'PSAppDeployToolkit\..+$')
            {
                Get-ChildItem -LiteralPath $_.FullName -Recurse -File | Unblock-File -ErrorAction Ignore
                Import-Module -Name $_.FullName -Force
            }
        }
    }

    # Invoke the deployment and close out the session.
    & "$($adtSession.DeploymentType)-ADTDeployment"
    Close-ADTSession
}
catch
{
    # An unhandled error has been caught.
    $mainErrorMessage = "An unhandled error within [$($MyInvocation.MyCommand.Name)] has occurred.`n$(Resolve-ADTErrorRecord -ErrorRecord $_)"
    Write-ADTLogEntry -Message $mainErrorMessage -Severity 3

    ## Error details hidden from the user by default. Show a simple dialog with full stack trace:
    # Show-ADTDialogBox -Text $mainErrorMessage -Icon Stop -NoWait

    ## Or, a themed dialog with basic error message:
    # Show-ADTInstallationPrompt -Message "$($adtSession.DeploymentType) failed at line $($_.InvocationInfo.ScriptLineNumber), char $($_.InvocationInfo.OffsetInLine):`n$($_.InvocationInfo.Line.Trim())`n`nMessage:`n$($_.Exception.Message)" -MessageAlignment Left -ButtonRightText OK -Icon Error -NoWait

    Close-ADTSession -ExitCode 60001
}

Ok, all the hard work is done and now you can install or uninstall Python 3.10 using one single PowerShell script. Simply change the DeploymentType parameter to install or uninstall. Logging functionality is built-in automatically and you can view the log files under “C:\Windows\Logs\Software”.


Python 3.10 NonInteractive Install (PSADT v4)

NonInteractive means Very Silent, i.e. no blocking apps. This is automatically set if it is detected that the process is not running in the user session and it is not possible for anyone to provide input using a mouse or keyboard.

  • Open Windows PowerShell by Right-Clicking on Windows PowerShell and selecting Run as Administrator
  • Change the directory to “C:\Temp\Python310”
    • PS C:\Temp\Python310>
  • Enter one of the following commands:
.\Invoke-AppDeployToolkit.exe -DeploymentType "Install" -DeployMode "NonInteractive"
Powershell.exe -ExecutionPolicy Bypass .\Invoke-AppDeployToolkit.ps1 -DeploymentType "Install" -DeployMode "NonInteractive"

Python 3.10 Silent Install (PSADT v4)

Silent means no dialogs (progress and balloon tip notifications are suppressed).

  • Open Windows PowerShell by Right-Clicking on Windows PowerShell and selecting Run as Administrator
  • Change the directory to “C:\Temp\Python310
    • PS C:\Temp\Python310>
  • Enter one of the following commands:
.\Invoke-AppDeployToolkit.exe -DeploymentType "Install" -DeployMode "Silent"
Powershell.exe -ExecutionPolicy Bypass .\Invoke-AppDeployToolkit.ps1 -DeploymentType "Install" -DeployMode "Silent"

Python 3.10 Interactive Install (PSADT v4)

Interactive means the install will show dialogs including progress and balloon tip notifications.

  • Open Windows PowerShell by Right-Clicking on Windows PowerShell and selecting Run as Administrator
  • Change the directory to “C:\Temp\Python310
    • PS C:\Temp\Python310>
  • Enter one of the following commands:
.\Invoke-AppDeployToolkit.exe -DeploymentType "Install" -DeployMode "Interactive"
Powershell.exe -ExecutionPolicy Bypass .\Invoke-AppDeployToolkit.ps1 -DeploymentType "Install" -DeployMode "Interactive"

How to Uninstall Python 3.10 Using the PowerShell App Deployment Toolkit v4

Python 3.10 NonInteractive Uninstall (PSADT v4)

NonInteractive means Very Silent, i.e. no blocking apps. This is automatically set if it is detected that the process is not running in the user session and it is not possible for anyone to provide input using a mouse or keyboard.

  • Open Windows PowerShell by Right-Clicking on Windows PowerShell and selecting Run as Administrator
  • Change the directory to “C:\Temp\Python310
    • PS C:\Temp\Python310>
  • Enter one of the following commands:
.\Invoke-AppDeployToolkit.exe -DeploymentType "Uninstall" -DeployMode "NonInteractive"
Powershell.exe -ExecutionPolicy Bypass .\Invoke-AppDeployToolkit.ps1 -DeploymentType "Uninstall" -DeployMode "NonInteractive"

Python 3.10 Silent Uninstall (PSADT v4)

Silent means no dialogs (progress and balloon tip notifications are suppressed).

  • Open Windows PowerShell by Right-Clicking on Windows PowerShell and selecting Run as Administrator
  • Change the directory to “C:\Temp\Python310
    • PS C:\Temp\Python310>
  • Enter one of the following commands:
.\Invoke-AppDeployToolkit.exe -DeploymentType "Uninstall" -DeployMode "Silent"
Powershell.exe -ExecutionPolicy Bypass .\Invoke-AppDeployToolkit.ps1 -DeploymentType "Uninstall" -DeployMode "Silent"

Python 3.10 Interactive Uninstall (PSADT v4)

Interactive means the install will show dialogs including progress and balloon tip notifications.

  • Open Windows PowerShell by Right-Clicking on Windows PowerShell and selecting Run as Administrator
  • Change the directory to “C:\Temp\Python310
    • PS C:\Temp\Python310>
  • Enter one of the following commands:
.\Invoke-AppDeployToolkit.exe -DeploymentType "Uninstall" -DeployMode "Interactive"
Powershell.exe -ExecutionPolicy Bypass .\Invoke-AppDeployToolkit.ps1 -DeploymentType "Uninstall" -DeployMode "Interactive"

Always make sure to test everything in a development environment prior to implementing anything into production. The information in this article is provided “As Is” without warranty of any kind.