OfficeDev / Office-IT-Pro-Deployment-Scripts

A collection of useful PowerShell scripts to make deploying Office 2016 and Office 365 ProPlus easier for IT Pros and administrators. If you have any feature requests or ideas for future scripts please add the idea to the issues list in this repository
http://officedev.github.io/Office-IT-Pro-Deployment-Scripts
MIT License
882 stars 838 forks source link

Office 2016 MSI removal loops unnecessarily #313

Open jameschappy opened 6 years ago

jameschappy commented 6 years ago

Hello,

We are using remove-previousofficeinstalls. We are replacing a number of office versions with 2016 CTR (including 2016 MSI).

We noticed that the powershell script invokes OffScrub_016msi numerous times. Even though it completes successfully the first time.

The following snippit of code sets '$office16Removed = $true' once OffScrub_016msi has been invoked. However, the code does not check for the existence of the variable in the next loop and runs OffScrub_016msi again (25 times in our example).

We have wrapped everything in another 'if (!$office16removed)' condition and it seems to have resolved the issue. Cheers

"16.*"{ if($Remove2016Installs){ if($product.ClickToRun -eq $true){ $c2r2016Installed = $true }

                            if(!$c2r2016Installed){
                                $ActionFile = "$scriptPath\$16MSIVBS"
                            } else {
                                if($RemoveClickToRunVersions){
                                    $ActionFile = "$scriptPath\$c2rVBS"  
                                } else {
                                    WriteToLogFile -LNumber $(LINENUM) -FName $currentFileName -ActionError "Office 2016 cannot be removed if 2016 Click-To-Run is installed. Use the -RemoveClickToRunVersions parameter to remove Click-To-Run installs." -LogFilePath $LogFilePath
                                    throw "Office 2016 cannot be removed if 2016 Click-To-Run is installed. Use the -RemoveClickToRunVersions parameter to remove Click-To-Run installs."
                                }
                            }

                            $cmdLine = """$ActionFile"" CLIENTALL $argList"
                            $cmd = "cmd /c cscript //Nologo $cmdLine"
                            Invoke-Expression $cmd
                            $office16Removed = $true
mikelagasse commented 6 years ago

Just wanted to add, I was experiencing the same issue with Office 2016 MSI removals and this change resolved.

deploymaster28 commented 5 years ago

Where you insert this if (!$office16removed) statement. I'm powershell newbie. I have checked this code exists in the script.`"16.*"{ if($Remove2016Installs){ if($product.ClickToRun -eq $true){ $c2r2016Installed = $true } if(!$c2r2016Installed){ $ActionFile = "$scriptPath\$16MSIVBS" } else { if($RemoveClickToRunVersions){ $ActionFile = "$scriptPath\$c2rVBS"
} else { WriteToLogFile -LNumber $(LINENUM) -FName $currentFileName -ActionError "Office 2016 cannot be removed if 2016 Click-To-Run is installed. Use the -RemoveClickToRunVersions parameter to remove Click-To-Run installs." -LogFilePath $LogFilePath throw "Office 2016 cannot be removed if 2016 Click-To-Run is installed. Use the -RemoveClickToRunVersions parameter to remove Click-To-Run installs." } }

                        $cmdLine = """$ActionFile"" CLIENTALL $argList"
                        $cmd = "cmd /c cscript //Nologo $cmdLine"
                        Invoke-Expression $cmd
                        $office16Removed = $true`
akhey commented 4 years ago

Where you insert this if (!$office16removed) statement. I'm powershell newbie. I have checked this code exists in the script.`"16.*"{ if($Remove2016Installs){ if($product.ClickToRun -eq $true){ $c2r2016Installed = $true } if(!$c2r2016Installed){ $ActionFile = "$scriptPath$16MSIVBS" } else { if($RemoveClickToRunVersions){ $ActionFile = "$scriptPath$c2rVBS" } else { WriteToLogFile -LNumber $(LINENUM) -FName $currentFileName -ActionError "Office 2016 cannot be removed if 2016 Click-To-Run is installed. Use the -RemoveClickToRunVersions parameter to remove Click-To-Run installs." -LogFilePath $LogFilePath throw "Office 2016 cannot be removed if 2016 Click-To-Run is installed. Use the -RemoveClickToRunVersions parameter to remove Click-To-Run installs." } }

                        $cmdLine = """$ActionFile"" CLIENTALL $argList"
                        $cmd = "cmd /c cscript //Nologo $cmdLine"
                        Invoke-Expression $cmd
                        $office16Removed = $true`

image