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

JavaScript: Build a Tribute Page

Demo: https:// codepen.io/dragoncoin/pen/EZJxYY HTML Code: <html><head> <body> <img src="http://www.animationxpress.com/wp-content/uploads/2015/10/Mahatma-Gandhi.jpg"> <h1>Mahatma Gandhi</h1> <div class="hidden"> <h2>"You must…

PowerShell: How to Change Active Directory Username

$oldUsername='testUser' $newUsername='tUser' function changeUsername{ param( $oldUsername, $newUsername ) $domainName=$env:USERDNSDOMAIN $newUserPrincipleName="$newUsername@$domainName" try{ Set-ADUser $oldUsername -SamAccountName $newUsername…

PowerShell: How To Stop and Start Palo Alto Cortex XDR Traps

$trapsAdminPassword='PASSWORDHERE', $trapsBin='C:\Program Files\Palo Alto Networks\Traps' function stopXdr{ param( $trapsAdminPassword, $trapsBin='C:\Program Files\Palo Alto Networks\Traps' ) echo…