Posted On January 30, 2023

PowerShell: Uninstall Program Using Its Name

kimconnect 0 comments
blog.KimConnect.com >> Codes , Windows >> PowerShell: Uninstall Program Using Its Name
# uninstallProgramUsingId.ps1

$appName='Virtual Machine Manager Agent'
$uninstallStringRegPaths='HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall','HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
$uninstallStrings=Get-ChildItem -Path $uninstallStringRegPaths
$uninstallString=($uninstallStrings|Get-ItemProperty|Where-Object {$_.DisplayName -match $appName}).UninstallString
if($uninstallString.count -eq 1){
    $appCode=[regex]::match($uninstallString,'\{(.*)\}').Value
    $uninstallCommand="& msiexec.exe /x $appCode /quiet /norestart"
    write-host "Invoking uninstall Command: $uninstallCommand"
    Invoke-Expression $uninstallCommand
    $appStillExists=Get-WmiObject -Class Win32_Product -Filter "Name='$appName'"
    if($appStillExists){
        write-warning "Uninstall has been unsuccessful at removing $appName"
        return $false
    }else{
        return $true
    }
}else{
    write-warning "Please check this/these uninstall string(s):`r`n$uninstallString"
    return $false
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Chicken Scratch Ports Scanner

Although there are optimized applications to perform this task such as Angry Port Scanner, NMAP,…

Windows File System Symlink Settings

Issue: Shortcuts or symbolic links are inaccessible at the destination, after being synchronized (using robocopy,…

PowerShell: Install TightVNC on Windows via CLI

Install VNC Server on the Remote Windows: # Access Remote Server via WinRM$SHERVERNAME = "SHERVER007"$winRMHttp=5985$winRMHttps=5986#…