Bash, Jamf, Office

Upgrading Office 2016 to 2019….and Kill 2011

Our environment is a little funky. In addition to still having Office 2011 out in the wild, we never deployed Office 2016 as a suite. This meant that users could choose to install Word or Excel or PowerPoint individually.

Historically, for Office 2016, we would push out updates individually for each application and just use smart groups in Jamf Pro to target those updates.

Given that Microsoft Office 2019 is more of an upgrade than an update, we must include a serializer for the 2019 applications. In addition to licensing Office 2019, the serializer also removes the license for the 2016 applications.

So if you have Word, Excel and PowerPoint all installed but only upgrade Word to 2019, you will have unlicensed Excel and PowerPoint.

So what’s the solution?

While it may not be perfect, I have whipped up a script for our environment that performs the following functions.

  • If any Office application is already on 2019, skip it.
  • If any Office application is on 2016, upgrade it.
  • If any Office application is on 2011, remove it.
  • Finally, check for updates.

This script assumes that you are using Jamf Pro. We have used this to get everyone up to 2019 and will move to patch policies and MAU to update Office 2019 going forward.

The Office 2011 uninstaller can be found here.
The Office Update script can be found here.

#!/bin/bash

# The version you would like to check for to confirm 2019 is installed.
# This is the version we are deploying so this is the version we are checking for.
CURRENT_VERSION="21"
MS_WORD_2019_TRIGGER="triggerMicrosoftWord2019"
MS_EXCEL_2019_TRIGGER="triggerMicrosoftExcel2019"
MS_POWERPOINT_2019_TRIGGER="triggerMicrosoftPowerPoint2019"
MS_SERIALIZER_TRIGGER="triggerMicrosoftOfficeSerializer"
REMOVE_OFFICE_2011_TRIGGER="triggerUninstallOffice2011"

MS_WORD_VERS=$(defaults read /Applications/Microsoft\ Word.app/Contents/Info.plist CFBundleVersion | cut -c -5 | cut -c 4-)
MS_EXCEL_VERS=$(defaults read /Applications/Microsoft\ Excel.app/Contents/Info.plist CFBundleVersion | cut -c -5 | cut -c 4-)
MS_POWERPOINT_VERS=$(defaults read /Applications/Microsoft\ PowerPoint.app/Contents/Info.plist CFBundleVersion | cut -c -5 | cut -c 4-)
OFFICE_2011=$(ls /Applications | grep "Microsoft Office 2011")
LICENSE_TYPE=""

PERPETUALLICENSE="/Library/Preferences/com.microsoft.office.licensingV2.plist"

# Determines what type of perpetual license the machine has installed

if [ -f "$PERPETUALLICENSE" ]; then
	/bin/cat "$PERPETUALLICENSE" | /usr/bin/grep -q "A7vRjN2l/dCJHZOm8LKan11/zCYPCRpyChB6lOrgfi"
	if [ "$?" == "0" ]; then
			echo "Already licensed for 2019"
      LICENSE_TYPE="2019"
	fi
  /bin/cat "$PERPETUALLICENSE" | /usr/bin/grep -q "A7vRjN2l/dCJHZOm8LKan1Jax2s2f21lEF8Pe11Y+V"
	if [ "$?" == "0" ]; then
    echo "Office 2016 license found"
    LICENSE_TYPE="2016"
	fi
fi

if [[ $LICENSE_TYPE != "2019" ]]; then
  echo "2019 License Not Found"
  echo "Running the Microsoft Office Serializer..."
  sudo jamf policy -event $MS_SERIALIZER_TRIGGER
fi


if [[ -n $MS_WORD_VERS ]]; then
  echo "Microsoft Word Currently Installed..."
  if [[ $MS_WORD_VERS -lt $CURRENT_VERSION ]]; then
    echo "Microsoft Word is not the latest version"
    echo "Upgrading..."
    sudo jamf policy -event $MS_WORD_2019_TRIGGER
  else
    echo "Microsoft Word already on 2019"
    echo "Skipping upgrade"
  fi
else
  echo "Microsoft Word not currently intalled"
fi

if [[ -n $MS_EXCEL_VERS ]]; then
  echo "Microsoft Excel Currently Installed..."
  if [[ $MS_EXCEL_VERS -lt $CURRENT_VERSION ]]; then
    echo "Microsoft Excel is not the latest version"
    echo "Upgrading..."
    sudo jamf policy -event $MS_EXCEL_2019_TRIGGER
  else
    echo "Microsoft Excel already on 2019"
    echo "Skipping upgrade"
  fi
else
  echo "Microsoft Excel not currently intalled"
fi

if [[ -n $MS_POWERPOINT_VERS ]]; then
  echo "Microsoft PowerPoint Currently Installed..."
  if [[ $MS_POWERPOINT_VERS -lt $CURRENT_VERSION ]]; then
    echo "Microsoft PowerPoint is not the latest version"
    echo "Upgrading..."
    sudo jamf policy -event $MS_POWERPOINT_2019_TRIGGER
  else
    echo "Microsoft PowerPoint already on 2019"
    echo "Skipping upgrade"
  fi
else
  echo "Microsoft PowerPoint not currently intalled"
fi

if [[ -n $OFFICE_2011 ]]; then
  echo "Microsoft Office 2011 Currently Installed..."
  echo "Removing Office 2011"
  sudo jamf policy -event $REMOVE_OFFICE_2011_TRIGGER
else
  echo "Microsoft Office 2011 Not Currently Installed"
fi

sudo jamf policy -event triggerMicrosoftOfficeUpdates
Next Post

No Comments

Leave a Reply