Hi all
I have been tasked with making an uninstall script to remove all Lync data and files for an user. This is primarily to resolve Lync issues we often have in our organisation, and we would like to have a working script that a user can just run via Self Service if Lync is causing issues for their user account.
We have come across this Microsoft recommended list of items to remove...
https://support.microsoft.com/en-gb/kb/2691870
I have created a script to try and match this, except that we are NOT going to remove the Lync app. Since we just want to remove the user Lync data, as it is very rare for us that Lync application itself needs to be re-installed (majority of the time, it's the user data).
My problem? My scripting skills is not top notch as I would like it to be. I seem to be having issues in getting the script to remove a user's stored Keychains application password as it keeps failing for me.
Any advice or assistance would be greatly appreciated...
Many thanks
#!/bin/bash
#domain name
domain=name_of_your_domain
#current user logged in
loggedinuser=`ls -l /dev/console | awk '{ print $3 }'`
#user's email address
emailaddress=$( dscl "/Active Directory/$domain/All Domains/" -read /Users/$loggedinuser EMailAddress | awk 'BEGIN {FS=" "} {print $2}' | tr '[:upper:]' '[:lower:]' )
#remove user lync data files
if [ -e /Users/$loggedinuser/Library/Preferences/com.microsoft.Lync.plist ] ; then
echo "Removing user's com.microsoft.Lync.plist file..."
rm -R /Users/$loggedinuser/Library/Preferences/com.microsoft.Lync.plist
else
echo "No com.microsoft.Lync.plist file located"
fi
if [ -e /Users/$loggedinuser/Library/Preferences/ByHost/MicrosoftLyncRegistrationDB.* ] ; then
echo "Removing user's MicrosoftLyncRegistrationDB files..."
rm -R /Users/$loggedinuser/Library/Preferences/ByHost/MicrosoftLyncRegistrationDB.*
else
echo "No MicrosoftLyncRegistrationDB file located"
fi
if [ ! -e /Users/$loggedinuser/Library/Logs/Microsoft-Lync-0.log ] ; then
echo "No Microsoft-Lync log file located"
else
echo "Removing user's Microsoft-Lync log files..."
function rmlogs() {
for n
do
rm /Users/$loggedinuser/Library/Logs/Microsoft-Lync-${n}.log
done
}
rmlogs
fi
if [ -d /Users/$loggedinuser/Documents/Microsoft User Data ] ; then
echo "Removing user's Microsoft User Data directory..."
rm -R /Users/$loggedinuser/Documents/Microsoft User Data
else
echo "No Microsoft User Data directory located"
fi
#remove lync user stored password
echo "Removing user's stored lync keychain password..."
security delete-generic-password -a "Microsoft Lync" /Users/$loggedinuser/Library/Keychains/login.keychain
#remove lync KeyContainer
if [ -e /Users/$loggedinuser/Library/Keychains/OC_KeyContainer__* ] ; then
echo "Removing user's Lync KeyContainer..."
rm -R /Users/$loggedinuser/Library/Keychains/OC_KeyContainer__*
else
echo "No user Lync KeyContainer located"
fi
#remove lync keychain certificate
echo "Removing user's Keychain Lync Certificate..."
security delete-certificate -c $emailaddress /Users/$loggedinuser/Library/Keychains/login.keychain
exit 0