Script to remove Lync 2011 & Skype for Business Mac Beta

New Contributor III

If you are about to deploy Skype for Business Mac, you will first need to remove Lync 2011 and Skype for Business Mac Beta.

This is a script to remove all items listed on How to perform a clean uninstall of Lync for Mac 2011. In addition, it will remove the corresponding Skype for Business Mac Beta files. The script removes Apps, caches, cookies, Keychain entries, preferences, receipts and logs. (But not Dock items). There is a similar, more mature script with feedback posted on jamf Nation here, though it's not as thorough.

I've tested this script in my AD environment.

Feel free to improve upon this.

# script to remove items listed on "How to perform a clean uninstall of Lync for Mac 2011"
# 10/25/2016-added lines based on script Dave Fisher posted on Slack
# 10/25/2016-Lucas Vance from jamf support helped with cut commands for userEmail
# tested in an AD environment

# Pull current logged in user into 'user' variable.
user=`ls -l /dev/console | cut -d " " -f 4`

# #2 Kill Lync & SfB
killall "Microsoft Lync"
killall "Skype for Business"

# #3 Delete the Lync & SfB applications
rm -rf /Applications/Microsoft
rm -rf /Applications/Skype For

# #4 Delete caches, cookies, OC_KeyContainer, preferences, receipts & logs (if present) 
rm -rf /Users/$user/Library/Application Support/
rm -rf /Users/$user/Library/Cookies/
rm -rf /Users/$user/Library/Caches/
rm -rf /Users/$user/Library/Group Containers/UBF8T346G9.Office/Lync
rm -rf /Users/$user/Library/Logs/Microsoft-Lync*
rm -rf /Users/$user/Library/Preferences/ByHost/MicrosoftLync*
rm -rf /Users/$user/Library/Preferences/
rm -rf /Users/$user/Library/Receipts/Lync.Client.Plugin.plist
rm -rf /Users/$user/Library/Keychains/OC_KeyContainer*

rm -rf /Users/$user/Library/Preferences/
rm -rf /Users/$user/Library/Logs/
rm -rf /Users/$user/Library/Application Support/Skype for Business
rm -rf /Users/$user/Library/Application Support/
rm -rf /Users/$user/Library/Application Support/
rm -rf /Users/$user/Library/Cookies/

# #5 Delete Lync & Skype User Data (but keep Lync Conversation History)
rm -rf /Users/$user/Documents/Microsoft User Data/Microsoft Lync Data 
rm -rf /Users/$user/Documents/Microsoft User Data/Microsoft/Communicator

# #6 remove this file from the Keychains folder and therefore, the Keychain
rm /Users/$user/Library/Keychains/OC_KeyContainer*

# #7 Delete the following KeyChain entry using security command
# $user variable is still in place from earlier

# Pull current logged in user's e-mail address into 'userEmail' variable.
userEmail=$(dscl . -read /Users/$user EMailAddress | cut -f2 -d":" | cut -f2 -d" ")
security delete-certificate -c $userEmail /Users/$user/Library/Keychains/login.keychain
security delete-generic-password -l "OC_KeyContainer*" /Users/$user/Library/Keychains/login.keychain

Contributor II

@marc_grubb thanks for this…any idea when we might actually see the release of Skype for Business on the Mac?

Contributor II

oops see that it was just announced.

rm -rf /Users/$user/Library/Preferences/

just missing t at the end there.

does anyone know where is the user's plist file for Skype for Business?

New Contributor

These two files seem to be involved.

If you click 'Delete Sign-In Info' at the login screen this is the only file that seems to be modified.
~/Library/Containers/ Support/Skype for Business/offlinestorageNormal.dat

However the 'Enter your Email Address' and 'Enter your User Name' fields still remember the user details, until you rename/delete this.
~/Library/Containers/ Support/


@marc_grubb Thanks for this. are you automatically logging in your users? I used to have a script that automatically logged in my users, but now with the new SFB doesn't seem to work.

New Contributor II

I get an error when running the script:

rm: /Users/<username>/Library/Keychains/OC_KeyContainer*: No such file or directory
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.

The OC_KeyContainer file is there, but it also contains the email address. I'm assuming the wild card should get this?

Not sure about the security error.

Any thoughts?

New Contributor III

@khey Thanks for catching that typo. I corrected it.
@mrbill I see that error too. As far as I can tell, it's benign and the remainder of the script works correctly.

New Contributor

Hi, Thanks for posting this script, it works to a point, but I am struggling with the last part, security delete-generic-password -l "OC_KeyContainer*" /Users/$user/Library/Keychains/login.keychain - the wildcard is not picking up the keychain object.
If i put the full name it finds it and removes it. Any ideas on how to get this working?

Thanks for any replies :)