pythonpowershelluninstallstring

Attempting to Silently Uninstall Python, but I get the error "You cannot call a method on a null-valued expression."


I am trying to push an uninstallation script org wide to remove python. Because this is happening on the backend, I need it to uninstall silently. What am I doing wrong? Thanks for any help in advance.

    $Programs = $SearchList | ?{$_.DisplayName -match ($ProgramName -join "|")}
Write-Output "Programs Found: $($Programs.DisplayName -join ", ")`n`n"

Foreach ($Program in $Programs)
{
If (Test-Path $Program.PSPath)
{
Write-Output "Registry Path: $($Program.PSPath | Convert-Path)"
Write-Output "Installed Location: $($Program.InstallLocation)"
Write-Output "Program: $($Program.DisplayName)"
Write-Output "Uninstall Command: $($Program.UninstallString)"

$UninstallString = $_.GetValue('UninstallString')
$isExeOnly = Test-Path -LiteralPath $UninstallString
if ($isExeOnly)
{
$UninstallString = "'$UninstallString'"
}
$UninstallString += '/quiet'

$Uninstall = (Start-Process cmd.exe -ArgumentList '/c', $Program.UninstallString -Wait -PassThru) 
<#Runs the uninstall command located in the uninstall string of the program's uninstall registry key, this is the command that is ran when you uninstall from Control Panel.
If the uninstall string doesn't contain the correct command and parameters for silent uninstallation, then when PDQ Deploy runs it, it may hang, most likely due to a popup.#>

Solution

  • There are several problems: