Forum Discussion

net-1994's avatar
net-1994
Copper Contributor
Apr 15, 2021
Solved

Scripting software uninstalls - How?

Hello All – We need to uninstall a program from over 1k Windows PCs.  Traditionally we could do this via running a MSI command on the local pc via script or SCCM.  e.g.: Msiexec.exe /x {%ProgramToRem...
  • net-1994's avatar
    Apr 17, 2021

    After some excruciating trial and error, we found the below script that did the trick! Simple and elegant and quick. No need to install the NuGet module on systems. Copy and pasted this into our task sequence step in SCCM/MECM, and good to go! If you want to use for your own purposes, just replace 'TeamViewer Host" in the script with the name of the program you want to get rid of. This only works with MSI installed programs, not EXEs.

     

    $uninstall32 = gci "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "TeamViewer Host" } | select UninstallString
    $uninstall64 = gci "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "TeamViewer Host" } | select UninstallString

    if ($uninstall64) {
    $uninstall64 = $uninstall64.UninstallString -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
    $uninstall64 = $uninstall64.Trim()
    Write "Uninstalling..."
    start-process "msiexec.exe" -arg "/X $uninstall64 /qn" -Wait}
    if ($uninstall32) {
    $uninstall32 = $uninstall32.UninstallString -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
    $uninstall32 = $uninstall32.Trim()
    Write "Uninstalling..."
    start-process "msiexec.exe" -arg "/X $uninstall32 /qn" -Wait}

Resources