Skip to main content

Lync for mac removal script

Hello all,
   Here's a little script that cleans out Lync for mac from OS X, this has been tested on 10.8 and 10.7 and found to be working very well, this basically automates the steps listed here:

http://mac2.microsoft.com/help/office/14/en-us/lyncdeploy/item/b4b71856-a7a5-467e-8425-238b3eaaa993?category=8cd683fd-c4a6-4520-a360-ac81632dadcb

#!/bin/bash

# See Microsoft Article ID: 2691870 How to perform a clean uninstall of Lync for Mac 2011
ASROOT=${ASROOT:-sudo}
# Variables and Functions #
VISIBLEUSERS=$(sudo /usr/bin/dscl . list /Users UniqueID | awk '$2 >= 500 && $2 < 100000000000000000 { print $1; }')
function LyncRunningCheck {
ps ax | grep -v grep | grep -i "/Applications/Microsoft Lync.app/Contents/MacOS/Microsoft Lync" > /dev/null
result=$?
if [ "${result}" -eq "1" ] ; then
     echo "`date`: Microsoft Lync is not running."
else
     echo "`date`: Killing Microsoft Lync."
 LyncPID=$(ps -A | grep -m1 "Microsoft Lync" | awk '{print $1}')
 sudo kill -9 $LyncPID
fi
}
# Main Process #

# Check if Lync is running, kill if it is:
LyncRunningCheck
# Delete the application:
rm -rf /Applications/Microsoft\ Lync.app/
echo "`date`: Removed /Applications/Microsoft\ Lync.app/"
rm -f /Library/Preferences/MicrosoftLyncRegistrationDB.plist

# Remove Dock Icon:
for username in $VISIBLEUSERS
do
HOMEFOLDER=$(sudo dscl . -read /Users/$username NFSHomeDirectory | awk '{print $2}')
DOCKSLOTS=$(sudo defaults read $HOMEFOLDER/Library/Preferences/com.apple.dock persistent-apps | grep tile-type | awk '/file-tile/ {print NR}')
for  slot in $DOCKSLOTS
do
DOCKPATH=`sudo /usr/libexec/PlistBuddy -c "print persistent-apps:$[$slot-1]:tile-data:file-data:_CFURLString" $HOMEFOLDER/Library/Preferences/com.apple.dock.plist`
if [[ $DOCKPATH =~ "Microsoft%20Lync.app" ]];
then
sudo /usr/libexec/PlistBuddy -c "Delete persistent-apps:$[$slot-1]" $HOMEFOLDER/Library/Preferences/com.apple.dock.plist
fi
done
echo "`date`: Removed Lync from $username dock"
done
sleep 5
sudo killall Dock -HUP
# Check if Lync is running, kill if it is:
LyncRunningCheck
# Delete the Application:
sudo rm -rf /Applications/Microsoft\ Lync.app/
echo "`date`: Removed /Applications/Microsoft\ Lync.app/"
# Remove Dock Icon:
for username in $VISIBLEUSERS
do
HOMEFOLDER=$(sudo dscl . -read /Users/$username NFSHomeDirectory | awk '{print $2}')
DOCKSLOTS=$(sudo defaults read $HOMEFOLDER/Library/Preferences/com.apple.dock persistent-apps | grep tile-type | awk '/file-tile/ {print NR}')
for  slot in $DOCKSLOTS
do
DOCKPATH=`sudo /usr/libexec/PlistBuddy -c "print persistent-apps:$[$slot-1]:tile-data:file-data:_CFURLString" $HOMEFOLDER/Library/Preferences/com.apple.dock.plist`
if [[ $DOCKPATH =~ "Microsoft%20Lync.app" ]];
then
sudo /usr/libexec/PlistBuddy -c "Delete persistent-apps:$[$slot-1]" $HOMEFOLDER/Library/Preferences/com.apple.dock.plist
fi
done
echo "`date`: Removed Lync from $username dock"
# Remove User Data:
rm -rf $HOMEFOLDER/Library/Preferences/ByHost/MicrosoftLyncRegistrationDB.*.plist
rm -rf $HOMEFOLDER/Library/Preferences/MicrosoftLyncRegistrationDB.plist
rm -rf $HOMEFOLDER/Library/Preferences/com.microsoft.Lync.plist
rm -rf $HOMEFOLDER/Library/Logs/Microsoft-Lync-*.log
rm -rf $HOMEFOLDER/Documents/Microsoft\ User\ Data/Microsoft\ Lync\ Data/
rm -rf $HOMEFOLDER/Documents/Microsoft\ User\ Data/Microsoft\ Lync\ History/
rm -rf $HOMEFOLDER/Keychains/OC_KeyContainer*
echo "`date`: Removed $username's preferences, logs, history and keychains"
# Remove Presence Handler:
HANDLERS=$(sudo /usr/libexec/PlistBuddy -c "print" $HOMEFOLDER/Library/Preferences/com.apple.LaunchServices.plist | grep Dict | awk '{print NR}')
for  handler in $HANDLERS
do
HandlerCheck=`sudo /usr/libexec/PlistBuddy -c "print LSHandlers:$[$handler-1]:LSHandlerRollAll" $HOMEFOLDER/Library/Preferences/com.apple.LaunchServices.plist`
if [[ $HandlerCheck =~ "com.microsoft.lync" ]];
then
sudo /usr/libexec/PlistBuddy -c "Delete LSHandlers:$[$handler-1]" $HOMEFOLDER/Library/Preferences/com.apple.LaunchServices.plist
echo "`date`: $username x-mspresence handler removed."
fi
done
done
sleep 5
sudo killall Dock -HUP
exit 0

                                                                                                                                                                                                                  Run the script by pasting it into a text editor, saving it as .sh and then making it executable by chmod +x lync_removal.sh, run it using: sh lync_removal.sh from the terminal.
This works silently so there won't be any popup window at all.
I am still working on removing keychain entries for Lync, but have found no way of doing this without serious risk on nuking the keychain.

Comments

  1. Cleaned up script:

    #!/bin/bash

    LYNC_PID=$(ps ax | grep "/Applications/Microsoft Lync.app/Contents/MacOS/Microsoft Lync" | grep -v grep | awk '{ print $1 }')
    kill -9 ${LYNC_PID} 2>/dev/null

    USER_LIST=`dscl . list /Users UniqueID | awk '$2 > 500 { print $1 }'`
    for USER in ${USER_LIST};
    do
    rm -rf "/Users/$USER/Library/Preferences/com.microsoft.Lync.plist" 2>/dev/null
    rm -rf "/Users/$USER/Library/Preferences/ByHost"/MicrosoftLyncRegistrationDB.*.plist 2>/dev/null
    rm -rf "/Users/$USER/Library/Logs"/Microsoft-Lync*.log* 2>/dev/null
    rm -rf "/Users/$USER/Documents/Microsoft User Data/Microsoft Lync Data" 2>/dev/null
    rm -rf "/Users/$USER/Documents/Microsoft User Data/Microsoft Lync History" 2>/dev/null
    rm -rf "/Users/$USER/Library/Keychains/"OC* 2>/dev/null
    done

    rm -R "/Applications/Microsoft Lync.app" 2>/dev/null
    rm -R "/Library/Internet Plug-Ins/MeetingJoinPlugin.plugin" 2>/dev/null

    exit 0

    ReplyDelete
  2. This is perfect. thanks for posting

    ReplyDelete
  3. This is perfect. thanks for posting

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete

Post a Comment

Popular posts from this blog

Removing corporate wireless restrictions completely : "The policies of your network prevent the creation of ad hoc (computer-to-computer) networks. For more information, contact your system administrator."

So i was recently tasked with removing wireless restrictions from a VP's windows 7 laptop that some infrastructure company had placed while contracted with our network, since he needed to enable setting up of adhoc connections on his laptop and he always got

"The policies of your network prevent the creation of ad hoc (computer-to-computer) networks. For more information, contact your system administrator."


A little bit of probing revealed that adhoc and peer to peer connections were blocked as evidenced by the the command 

netsh wlan show filter on an  elevated command prompt revealed that adhoc network type was blocked by group policy:

I removed the restrictions by:

1: open services.msc as administrator, scroll down to WLAN AutoConfig:

Migrating Outlook Profile to Office 365

We had a migration from Hosted Exchange to Office 365 and i was tasked with automating the local Outloook profile migration for Users:

I Created a GUI utility using powershell which would allow users to create an Office365 Profile and set it as default, I prepared PRF files for each version of office and an autodiscover.xml to be used for local autodiscover and uploaded them to a hosted site:

The PRF file to set settings for Office 365 are hard to find: i used the below entries:


;AutomaticallygeneratedPRFfilefromtheMicrosoftOfficeCustomizationandInstallationWizard;**************************************************************;Section1-ProfileDefaults;**************************************************************[General]Custom=1ProfileName=%UserName%-O365DefaultProfile=YesOverwriteProfile=YesModifyDefaultProfileIfPresent=false;**************************************************************;Section2-ServicesinProfile;**************************************************************[Service…

To Unlock Windows Update locked due to group policy.

To Unlock Windows Update locked due to group policy.




Open gpedit.msc and browse to the location /Computer Configuration/Administrative Templates/System/Internet Communication Management/Internet Communication Settings and double click "turn off access to all windows update features" and set it to disabled.