Modify Microsoft Office 2016 - script

This simple script will let you modify local MS Office installation. As if you clicked Change in Add/Remove Programs. This allows you to save bandwidth and space since you dont need MS Office setup files because they are cached on the machine already. However, if you do not have it cached, you can include setup files also.

I will show you how to modify ProPlus edition of MS Office 32bit however for other editions, you just need to modify the product name and registry path.

The installation script is actually very simple. I will use Skype for Business as an example. In this case I had MS Office 2016 installed on the machines but only with Word,Excel,Outlook and Powerpoint. The entire installation gets cached to $envSystemDrive\MSOCache. You can use that setup to modify it or you can have the installation files with your toolkit. Modify the path if that is the case.

In preinstallation we check whether MSOffice 2016 is installed by checking registry and terminate the installation if not:

		## <Perform Pre-Installation tasks here>
		If (-not (Get-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Office16.PROPLUS" -ea SilentlyContinue)) {
			Throw "Microsoft Office 2016 32bit is not installed or corrupted. Cannot continue."
		}

Now there is a chance that this entry exists but the product is already uninstalled. However if that is the case then the next step should fail since if there is no office installed then there should be no cached files. So we check whether the setup is cache and run it with our config that only changes Skype For Business:

		## <Perform Installation tasks here>
		Write-Log "$appVendor $appName $appVersion installation started..."
		if (Test-Path -Path "$envSystemDrive\MSOCache\All Users\{90160000-0011-0000-0000-0000000FF1CE}-C\Setup.exe" -PathType Leaf) {
			Execute-Process -Path "$envSystemDrive\MSOCache\All Users\{90160000-0011-0000-0000-0000000FF1CE}-C\Setup.exe" -Parameters "/modify `"ProPlus`" /config `"$dirFiles\skypeforbusinessinstall.xml`""
		} else {
			Throw "Microsoft Office 2016 32bit is not installed or corrupted. The installation cache does not exist. Cannot continue."
		}

The xml file looks like this:

<Configuration Product="ProPlus">
<OptionState Id="LyncCoreFiles" State="local" Children="force" />
<Updates Enabled="FALSE" Branch="Current" />
<Display Level="None" AcceptEULA="TRUE" CompletionNotice="no" SuppressModal="yes"/>
<Setting Id="SETUP_REBOOT" Value="Never" />
</Configuration>

Of course if you are not using ProPlus edition then change the product in all places.
Now lets go line by line through the config:
OptionState specifies the product to change. Parameter State can be local and absent. Local means it will be installed and absent will make setup uninstall the feature. Parameter Children specifies behavior for all subfeatures. The list of all IDs for OptionState can be found inside setup.xml that resides within your Office installation files, inside the main folder .ww For ProPlus it would be ProPlus.WW
Updates specifies whether the setup should download updates and parameter Branch obviously specifies the branch.
Display shows what to show for the user when it comes to UI of the installation. Since we use Show-InstallationProgress, everything else should be silent and install in background so that line is setup to hide everything.
Setting is used to change setup variables and settings. In this case we make sure that reboot is not started forcefully. We will still get 3010 if the reboot is needed.

Uninstallation looks almost the same:

		# <Perform Uninstallation tasks here>
		Write-Log "$appVendor $appName $appVersion uninstallation started..."
		if (Test-Path -Path "$envSystemDrive\MSOCache\All Users\{90160000-0011-0000-0000-0000000FF1CE}-C\Setup.exe" -PathType Leaf) {
			Execute-Process -Path "$envSystemDrive\MSOCache\All Users\{90160000-0011-0000-0000-0000000FF1CE}-C\Setup.exe" -Parameters "/modify `"ProPlus`" /config `"$dirFiles\skypeforbusinessuninstall.xml`""
		}else {
			Throw "Microsoft Office 2016 32bit is not installed or corrupted. The installation cache does not exist. Cannot continue."
		}

We just need a different config file:

<Configuration Product="ProPlus">
<OptionState Id="LyncCoreFiles" State="absent" Children="force" />
<Updates Enabled="FALSE" Branch="Current" />
<Display Level="None" AcceptEULA="TRUE" CompletionNotice="no" SuppressModal="yes"/>
<Setting Id="SETUP_REBOOT" Value="Never" />
</Configuration>

The config file can also be used for installation. In that case you dont need the /modify parameter or to check whether it is installed on the machine and you have to target the ms office setup in the $dirFiles.

Thanks a lot :smiley:

1 Like