#!/bin/bash 

rm -R "/Applications/Microsoft Excel.app"
rm -R "/Applications/Microsoft OneNote.app"
rm -R "/Applications/Microsoft Outlook.app"
rm -R "/Applications/Microsoft PowerPoint.app"
rm -R "/Applications/Microsoft Word.app"

rm "/Library/LaunchDaemons/com.microsoft.office.licensingV2.helper.plist"
rm "/Library/LaunchDaemons/com.microsoft.autoupdate.helper.plist"
rm "/Library/PrivilegedHelperTools/com.microsoft.office.licensingV2.helper"
rm "/Library/PrivilegedHelperTools/com.microsoft.autoupdate.helper"
rm "/Library/Preferences/com.microsoft.office.licensingV2.plist"

IFS=":" 
for user in $(dscl . list /Users | grep -v _ | tr "\n" ":" ); do
    [ -e "/Users/${user}" ] || continue
    
    rm -R "/Users/${user}/Library/Containers/com.microsoft.errorreporting"
    rm -R "/Users/${user}/Library/Containers/com.microsoft.Excel"
    rm -R "/Users/${user}/Library/Containers/com.microsoft.netlib.shipassertprocess"
    rm -R "/Users/${user}/Library/Containers/com.microsoft.Office365ServiceV2"
    rm -R "/Users/${user}/Library/Containers/com.microsoft.Outlook"
    rm -R "/Users/${user}/Library/Containers/com.microsoft.Powerpoint"
    rm -R "/Users/${user}/Library/Containers/com.microsoft.RMS-XPCService"
    rm -R "/Users/${user}/Library/Containers/com.microsoft.Word"
    rm -R "/Users/${user}/Library/Containers/com.microsoft.onenote.mac"

    rm -R "/Users/${user}/Library/Group Containers/UBF8T346G9.ms"
    rm -R "/Users/${user}/Library/Group Containers/UBF8T346G9.Office"
    rm -R "/Users/${user}/Library/Group Containers/UBF8T346G9.OfficeOsfWebHost"
done

for rcpts in $(ls "/var/db/receipts/" | grep com.microsoft.package.Microsoft_ | tr "\n" ":" ); do
   rm -r "/var/db/receipts/${rcpts}"
done 
unset IFS

security delete-generic-password -a 'Microsoft Office Identities Cache 2'
security delete-generic-password -a 'Microsoft Office Identities Settings 2'

exit 0
