I had this script working once to uninstall Office 2013 from registry but now it won't work

Viewed 523
$uninstall32 = gci "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "Microsoft Office Professional Plus 2013" } | select UninstallString

#$uninstall64 = gci "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "Microsoft Office Professional Plus 2013" } | 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 /quiet" -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 /quiet" -Wait}

But now when I run it, i get the command line switch for the uninstall 32 part. Not sure what changed, but it was nice that it got rid of all of Microsoft Office 2013 plus, now i have to rely on configuring the config file to uninstall it.

2 Answers

As per Olaf's comment, currently you get the reg value of the uninstall for 32bit but you then do nothing else as the #'s comment everything out. To the system all those lines are effectively blank.

Using your code, if you amend it to this it will do something at least:

$uninstall32 = gci "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "Microsoft Office Professional Plus 2013" } | select UninstallString

#$uninstall64 = gci "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "Microsoft Office Professional Plus 2013" } | 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 /quiet" -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 /quiet" -Wait

This will only do 32bit uninstalls.

Related