office 2016 uninstall script wanted

tcandela
Valued Contributor II

Anyone have or know where i can get a good office 2016 uninstall script?

I see a handful around but they all are different. Some look to just remove the /applications and user folders related to office 2016, while others remove /applications, user folders and system folders related to office 2016.

looking to have something that will remove office 2016 cleanly (via Self Service policy) to have office 2019 then installed with no issues (via Self Service Policy).

thank you

10 REPLIES 10

sdagley
Esteemed Contributor II

@tcandela Other that removing the license files you don't really need to remove 2016 before installing 2019. For removing the license files, @pbowden's Unlicense is the tool you want to use.

atomczynski
Valued Contributor

I've been doing this via Self Service

#!/bin/bash
if test “/Applications/Microsoft Excel.app”;then rm -rf /Applications/Microsoft Excel.app;fi
if test "/Applications/Microsoft OneNote.app";then rm -rf /Applications/Microsoft OneNote.app;fi
if test “/Applications/Microsoft Outlook.app”;then rm -rf /Applications/Microsoft Outlook.app;fi
if test "/Applications/Microsoft PowerPoint.app";then rm -rf /Applications/Microsoft PowerPoint.app;fi
if test "/Applications/Microsoft Word.app";then rm -rf /Applications/Microsoft Word.app;fi

mconners
Valued Contributor

Hello @tcandela this is what we have been using in both self service policies or in conjunction with installs of Office to remove all the cruft of previous installs, prior to the actual install:

!/bin/sh

This script will brute force remove all Microsoft related files from the local hardware. This is a destructive removal. Please save all work prior to running this.

Set the variables

procList="Microsoft"

procName=""

Check to see if either of those processes are running

for proc in "${procList[@]}"

do runningProc=$(ps axc | grep -i "$proc" | awk '{print $1}') if [[ $runningProc ]]; then echo "$proc is running with PID: ${runningProc}"

procName=$"$procName $proc"

kill -s HUP $runningProc else echo "$proc not running" fi
done

This section locates all of the Microsoft items located in the /Applications folder along with other locations, then deletes them.

array=(/Applications/Microsoft
/Library/Applications/OneDrive

/Library/Application Support/Microsoft
/Library/LaunchAgents/com.microsoft.

/Library/LaunchDaemons/com.microsoft.
/Library/Logs/Microsoft

/Library/Preferences/com.microsoft.
/Library/PrivilegedHelperTools/com.microsoft.

/private/var/root/Library/Group Containers/*.Office
)

for i in "${array[@]}"

do if [ -d "$i" ] then sudo rm -R "$i" else if [ -e "$i" ] then sudo rm -R "$i" else echo "No Additional Microsoft Files or Folders Found in $i." fi fi
done
exit

tcandela
Valued Contributor II

@mconners does that script also remove previous licensing information? for example licensing info from Office 2016?

is this good for uninstalling office 2019 also?

I don't want any possible license issues if 2016 is removed and 2019 is installed afterwards.

when either office version gets installed i use whichevers Office versions VL serializer.

mconners
Valued Contributor

@tcandela I don't believe it touches the license files. We have already migrated over to 2019 so for us, I didn't need to worry about licensing information. I would follow with what @sdagley mentioned above regarding the license removal piece. Then if you wish, you could run my script to remove additional files installed by Office.

Once a friend guided me along with the use of the array in the script, I have adapted it to other uninstalls and it has made the world of difference for me. Perhaps if you added into this script, the location of the license files, then you could remove them with a single script.

tcandela
Valued Contributor II

@atomczynski hi there, hey, the short bash script you wrote only removes the Office 2016 applications. Doesn't remove any system or user related office files. Are you just then installing another version say 2019 in it's place?

atomczynski
Valued Contributor

@tcandela Correct. We install the 2019 serializer tool and Office 2019 suite.

tcandela
Valued Contributor II

@atomczynski ok, so you're just removing the 2016 applications. Installing 2019 and VL serializer after the 2016 apps are removed will be fine?
Ive tested exactly that a couple days ago and 2019 installed and is VL licensed.

is each of your if statements doing a check if that particular office .app exists? I'm not 100% sure if that TEST command is making that check??? because on most of the macs here we don't install ONENOTE and OUTLOOK. but if a computer happens to have ONENOTE or OUTLOOK then RM it.

i don't see an 'else' clause, so wondering if a computer that doesn't have ONENOTE/OUTLOOK and gets to the RM line will the script continue or fail

atomczynski
Valued Contributor

@tcandela

I'm not sure if I can add anything to this now. If I can find a machine with old version of Office I'll dive into it.
I have a policy that installs the VL tool and then Office 2019.

tcandela
Valued Contributor II

@atomczynski no need to add to it, i know how. was just curious if you know what happens with the TEST command if the particular office application doesn't exist.