Skip to content

Instantly share code, notes, and snippets.

@karladler
Last active July 20, 2025 16:02
Show Gist options
  • Save karladler/e6eef68929b583ae3e4b3d350047f385 to your computer and use it in GitHub Desktop.
Save karladler/e6eef68929b583ae3e4b3d350047f385 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Microsoft Teams Cleanup Script
# This script removes all Microsoft Teams related cache, data, and preference files
# Based on analysis of actual Teams installations and Microsoft support documentation
# List of known Microsoft Teams-related folders (optimized - only shortest paths)
teams_folders=(
# Original Application Support folders
"$HOME/Library/Application Support/Microsoft/Teams"
# Caches
"$HOME/Library/Caches/com.microsoft.teams.shipit"
"$HOME/Library/Caches/com.microsoft.teams"
# Containers
"$HOME/Library/Containers/com.microsoft.teams2.respawn"
"$HOME/Library/Containers/com.microsoft.teams2"
"$HOME/Library/Containers/com.microsoft.teams2.notificationcenter"
# Group Containers
"$HOME/Library/Group Containers/UBF8T346G9.com.microsoft.oneauth"
"$HOME/Library/Group Containers/UBF8T346G9.com.microsoft.teams"
"$HOME/Library/Group Containers/UBF8T346G9.ms"
# Logs
"$HOME/Library/Logs/Microsoft Teams"
# Preferences
"$HOME/Library/Preferences/com.microsoft.teams.plist"
"$HOME/Library/Preferences/com.microsoft.teams.ShipIt.plist"
# Application Scripts
"$HOME/Library/Application Scripts/com.microsoft.teams2"
"$HOME/Library/Application Scripts/UBF8T346G9.com.microsoft.teams"
"$HOME/Library/Application Scripts/UBF8T346G9.com.microsoft.oneauth"
# Browser cache for Teams (Chrome)
"$HOME/Library/Application Support/Google/Chrome/Default/IndexedDB/https_teams.microsoft.com_0.indexeddb.leveldb"
"$HOME/Library/Application Support/Google/Chrome/Default/IndexedDB/https_teams.microsoft.com_0.indexeddb.blob"
"$HOME/Library/Application Support/Google/Chrome/Profile 1/IndexedDB/https_teams.microsoft.com_0.indexeddb.leveldb"
"$HOME/Library/Application Support/Google/Chrome/Default/IndexedDB/https_teams.live.com_0.indexeddb.leveldb"
# Additional cache and crash reporter files
"$HOME/Library/Application Support/CrashReporter/MSTeams_A00961D1-48AE-5C55-9BA3-E3A53F4AD00B.plist"
# Temporary helper files
"$HOME/Library/Containers/com.microsoft.teams2/Data/tmp/.com.microsoft.teams2.helper.*"
)
echo "Starting Enhanced Microsoft Teams cleanup..."
echo "This script will remove all Microsoft Teams related cache, data, and preference files."
echo "This includes:"
echo "- Application cache and data"
echo "- Browser cache for Teams"
echo "- Container data and preferences"
echo "- Crash reports and logs"
echo "- Temporary files"
echo ""
# Function to safely remove directories
remove_directory() {
local dir="$1"
if [ -e "$dir" ]; then
echo "Found: $dir"
read -p "Delete this folder? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Deleting: $dir"
rm -rf "$dir"
echo "✓ Deleted: $dir"
else
echo "Skipping: $dir"
fi
else
echo "Not found: $dir"
fi
}
# Process each folder
for folder in "${teams_folders[@]}"; do
# Handle wildcard patterns
if [[ "$folder" == *"*"* ]]; then
# Expand wildcards and process each match
for expanded_folder in $folder; do
if [ -e "$expanded_folder" ]; then
remove_directory "$expanded_folder"
fi
done
else
remove_directory "$folder"
fi
done
echo ""
echo "=== Keychain Cleanup ==="
echo "Do you want to delete OneAuthAccount from keychain?"
read -p "Delete OneAuthAccount? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
security delete-generic-password -s OneAuthAccount 2>/dev/null
echo "✓ OneAuthAccount deleted from keychain"
else
echo "Skipping OneAuthAccount deletion"
fi
echo "Do you want to delete additional Teams-related keychain entries?"
read -p "Delete Teams keychain entries? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
# Delete Teams-related keychain entries
security delete-generic-password -s "com.microsoft.teams2" 2>/dev/null || echo "No Teams2 keychain entry found"
security delete-generic-password -s "com.microsoft.teams" 2>/dev/null || echo "No Teams keychain entry found"
security delete-generic-password -s "UBF8T346G9.com.microsoft.teams" 2>/dev/null || echo "No Teams group container keychain entry found"
echo "✓ Teams keychain entries deleted"
else
echo "Skipping Teams keychain entries deletion"
fi
echo ""
echo "=== Additional Cleanup Options ==="
echo "Do you want to clear Teams browser cache for other browsers?"
read -p "Clear Teams browser cache? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
# Safari Teams cache
if [ -d "$HOME/Library/Safari/LocalStorage/https_teams.microsoft.com_0.localstorage" ]; then
rm -rf "$HOME/Library/Safari/LocalStorage/https_teams.microsoft.com_0.localstorage"
echo "✓ Safari Teams cache cleared"
fi
# Firefox Teams cache (if exists)
find "$HOME/Library/Application Support/Firefox" -name "*teams*" -type d 2>/dev/null | while read -r firefox_cache; do
rm -rf "$firefox_cache"
echo "✓ Firefox Teams cache cleared: $firefox_cache"
done
else
echo "Skipping browser cache cleanup"
fi
echo ""
echo "=== Cleanup Summary ==="
echo "Enhanced Microsoft Teams cleanup completed!"
echo ""
echo "Additional manual cleanup options:"
echo "1. Open Keychain Access to manually review and delete any remaining Teams-related entries:"
echo " open -a Keychain\\ Access"
echo ""
echo "2. Restart your computer to ensure all changes take effect"
echo ""
echo "3. If you're still experiencing issues, you may need to:"
echo " - Uninstall and reinstall Microsoft Teams"
echo " - Clear your browser cache completely"
echo " - Check for any remaining Teams processes: ps aux | grep -i teams"
echo ""
echo "Note: This script removes all Teams data. You will need to sign in again after cleanup."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment