Microsoft Teams (Work or School) removal script

mojo21221
Contributor II

Hey all, I have been using the tools at https://office-reset.com/macadmins/ for assisting with O365 and other office related issue. However, I was wondering if anyone has made a Microsoft Teams (Work or School) removal script? Office reset has a full office removal script, however it does not include he new Teams as part of the removal...  Main reason for wanting it is to get the mac back to a clean slate from the O365 perspective to troubleshoot some other issues. 

5 REPLIES 5

AJPinto
Honored Contributor II

We are just going to remove the Teams app with rm. Microsoft does not provide an uninstaller, you could use the office removal tool, but with Teams cleanup it should not be needed.

sudo rm -rf "/Applications/Microsoft Teams.app"

 

Thanks for the quick response AJ. I agree the office removal tool does a great job on removing Teams classic. However, I am looking to remove the new Microsoft Teams (Work or School). It looks like MS has made new locations for the behind the scenes files that make it work... Hence seeing if anyone has made a script. I tried dropping it into AppCleaner and seeing what files it finds, but wasnt sure if there are even more to remove... 

pete_c
Contributor III

Try this:

#!/bin/bash

autoload is-at-least
APP_NAME="Microsoft Teams (work or school)"

GetLoggedInUser() {
	LOGGEDIN=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/&&!/loginwindow/{print $3}')
	if [ "$LOGGEDIN" = "" ]; then
		echo "$USER"
	else
		echo "$LOGGEDIN"
	fi
}

SetHomeFolder() {
	HOME=$(dscl . read /Users/"$1" NFSHomeDirectory | cut -d ':' -f2 | cut -d ' ' -f2)
	if [ "$HOME" = "" ]; then
		if [ -d "/Users/$1" ]; then
			HOME="/Users/$1"
		else
			HOME=$(eval echo "~$1")
		fi
	fi
}


## Main
LoggedInUser=$(GetLoggedInUser)
SetHomeFolder "$LoggedInUser"
echo "Office-Reset: Running as: $LoggedInUser; Home Folder: $HOME"

/usr/bin/pkill -9 "${APP_NAME}"
/usr/bin/pkill -9 'Microsoft Teams Webview Helper'


echo "Office-Reset: Removing configuration data for ${APP_NAME}"
/bin/rm -rf "$HOME/Library/Application Scripts/com.microsoft.teams2"
/bin/rm -rf "$HOME/Library/Application Scripts/com.microsoft.teams2.launcher"
/bin/rm -rf "$HOME/Library/Application Scripts/com.microsoft.teams2.notificationcenter"
/bin/rm -rf "$HOME/Library/Containers/Microsoft Teams (work or school)"
/bin/rm -rf "$HOME/Library/Containers/Microsoft Teams Launcher"
/bin/rm -rf "$HOME/Library/Containers/com.microsoft.teams2.notificationcenter"
/bin/rm -rf "$HOME/Library/Group Containers/UBF8T346G9.com.microsoft.oneauth"
/bin/rm -rf "$HOME/Library/Group Containers/UBF8T346G9.com.microsoft.teams"
/bin/rm -rf "$HOME/Library/Preferences/com.microsoft.teams2.helper.pliszt"
/bin/rm -rf "$HOME/Library/Saved Application State/com.microsoft.teams2.savedState"
/bin/rm -rf "$HOME/Library/Saved Application State/com.microsoft.teams2.savedState"

KeychainHasLogin=$(/usr/bin/sudo -u "$LoggedInUser" /usr/bin/security list-keychains | grep 'login.keychain')
if [ "$KeychainHasLogin" = "" ]; then
	echo "Office-Reset: Adding user login keychain to list"
	/usr/bin/sudo -u "$LoggedInUser" /usr/bin/security list-keychains -s "$HOME/Library/Keychains/login.keychain-db"
fi

echo "Display list-keychains for logged-in user"
/usr/bin/sudo -u "$LoggedInUser" /usr/bin/security list-keychains

/usr/bin/sudo -u "$LoggedInUser" /usr/bin/security delete-generic-password -l 'Microsoft Teams Identities Cache'
/usr/bin/sudo -u "$LoggedInUser" /usr/bin/security delete-generic-password -l 'com.microsoft.teams.HockeySDK'
/usr/bin/sudo -u "$LoggedInUser" /usr/bin/security delete-generic-password -l 'com.microsoft.teams.helper.HockeySDK'

exit 0

 

 

pete_c
Contributor III

Remember that Jamf runs scripts as root, which the MS docs sort of neglect to mention.

sdagley
Esteemed Contributor II

@mojo21221 Paul Bowden, who works for Microsoft but created the Office-Reset site on his own, is out on medical leave, and he's not updating that site or the MacAdmins.software site he also created. He did however post a 2.0 Beta 1 version of the main removal tool (https://office-reset.com/download/Microsoft_Office_Reset_2.0.0.pkg) before going out and if you use a tool like Suspicious Package you can examine the various postinstall scripts in that package to see how they work, including the one updated for Microsoft Teams (Work or School).