Scripting software uninstalls - How?

Copper Contributor

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 {%ProgramToRemoveGUIDstring%}


However there are multiple versions in use with their own product GUID.  It would be a nightmare to try and get each unique ID and run them on the PCs.  Scripting seems the way to go.  So far we have tried (with success) two different PowerShell scripts:

$application = Get-WmiObject -Class Win32_Product -Filter "Name = 'TeamViewer Host'"



While the above works, we can’t use it due to it causing major issues. (See this: WMI Remove is EVIL)  Another PS that does work, but not well for us would be:

Get-Package -Name “Program Name” | Uninstall-Package


When the above runs, we are prompted to install the PS NuGet module, which our security team will not allow.  So can anyone think of any other PowerShell script that could do this for us?  Or hell even an old skool VBS/Cscript/Wscript?

2 Replies
best response confirmed by net-1994 (Copper Contributor)

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}

Hello @net-1994 


I was trying this script but I got a error:

Screenshot 2021-12-17 131929.png

Any idea?