Script to delete the address books

Sometimes, clearing out Lync or Skype for Business Address books on a client and downloading a new copy can be useful. Here's how to do it automatically.

====
There's a lot been written about the Lync or Skype for Business Address Books over the years, so I'll not go into that whole thing here. What I do get asked about though is clearing down address books on a client and downloading a clean copy. How can we do that automatically?

Well, firstly, you need to be aware of how those address books get downloaded. Have a read of this article here, it explains the background.

Downloading the Address Book in Lync 2013

While the above is for Lync 2013, the process is much the same for Skype for Business 2015.

Deleting the local copies of the address books involves deleting GalContacts.db and GalContacts.db.idx from the user's SIP profile directory. For Skype for Business 2015, this is in this location:

C:\Users\
username\AppData\Local\Microsoft\Office\15.0\Lync\sip_sipaddress

As we know that, it's pretty easy to automate.

I've written a script that will do this for you. You can download that script here.

AutoDelAddressBook.rar

The script also creates a log file of the work that it carries out. The below is an example output from the script:

==========================================================================================
17-Nov-15:2:18:58 PM: Delete GalContacts Script.
17-Nov-15:2:18:58 PM: Running on workstation: BERKPC
17-Nov-15:2:18:58 PM: User: *****
==========================================================================================
17-Nov-15:2:18:58 PM: Path root: C:\Users\*****\AppData\Local\Microsoft\Office\15.0\Lync\
17-Nov-15:2:18:58 PM: Temp Path: C:\Users\*****\AppData\Local\Temp
==========================================================================================
17-Nov-15:2:18:58 PM: Checking to see if TEMP file exists....
17-Nov-15:2:18:58 PM: Temp file does not exist.
17-Nov-15:2:18:58 PM: Getting directory of all SIP users...
17-Nov-15:2:18:58 PM: Command for directory: CMD.exe /c DIR C:\Users\*****\AppData\Local\Microsoft\Office\15.0\Lync\sip_* /b >C:\Users\*****\AppData\Local\Temp\GalContactsDel.TMP
17-Nov-15:2:18:58 PM: Running command....
17-Nov-15:2:18:58 PM: Checking to see if TEMP file exists....
17-Nov-15:2:18:58 PM: Temp file found, directory completed.
==========================================================================================
17-Nov-15:2:18:58 PM: Opening temp file, scanning for GalContacts file in each specified SIP directory...
17-Nov-15:2:18:58 PM: Working on: sip_***@*****.**.**
17-Nov-15:2:18:58 PM: Full Path: C:\Users\*****\AppData\Local\Microsoft\Office\15.0\Lync\sip_***@*****.**.**
17-Nov-15:2:18:58 PM: Could not find GalContacts.db in directory.
17-Nov-15:2:18:58 PM: Could not find GalContacts.db.idx in directory.
17-Nov-15:2:18:58 PM: Working on: sip_****@***.***
17-Nov-15:2:18:58 PM: Full Path: C:\Users\*****\AppData\Local\Microsoft\Office\15.0\Lync\sip_****@***.***
17-Nov-15:2:18:58 PM: Could not find GalContacts.db in directory.
17-Nov-15:2:18:58 PM: Could not find GalContacts.db.idx in directory.
17-Nov-15:2:18:58 PM: Working on: sip_****.********@***.***
17-Nov-15:2:18:58 PM: Full Path: C:\Users\*****\AppData\Local\Microsoft\Office\15.0\Lync\sip_****.********@***.***
17-Nov-15:2:18:58 PM: Could not find GalContacts.db in directory.
17-Nov-15:2:18:58 PM: Could not find GalContacts.db.idx in directory.
==========================================================================================
17-Nov-15:2:18:58 PM: Completed.
17-Nov-15:2:18:58 PM: Deleting temp file....
17-Nov-15:2:18:58 PM: Number of profiles scanned: 3
17-Nov-15:2:18:58 PM: Number of GalContacts.db deleted:0
17-Nov-15:2:18:58 PM: Number of GalContacts.db.idx deleted:0
==========================================================================================

What the script does is searches a user's home directory for all of the SIP identities, and then in those identities removes those GalContact files. The script tells you which profiles were scanned, and how many removed.

So, to use the script, the first thing you need to do is set up a shared directory for all of the log files. In my script currently, the logging directory is set to "\\BerkPC\Logging". You will need to edit line 16 to reflect the correct path for your logs.

'===========
'Set the LOGPATH Variable to the directory that you want to house the logging output files.
'Note do NOT include a trailing \
'I.e. \\unc\logs is OK \\unc\logs\ is NOT ok
'===========
LogPath="\\BerkPC\Logging"


Once it's set, you can fire the script at as many machines as you want - there's various ways of doing that, group policy objects for example. Remember that it needs to be executed under a user context not the machine one, as it's the user profiles we're interested in.






blog comments powered by Disqus