Script to Force Download of the Lync 2013 Address Book

In a previous article I wrote a script that forces Lync 2010 clients to update the Lync Server 2010 address book.



The Lync 2013 client not only changes the location where the address book is stored on the local machine, but changes the address book file name for Lync Server 2013, as well.



The script below sets the GALDownloadInitialDelay key in the registry to force the Lync client to download the address book immediately after signing in.  It then enumerates all the SIP_* sub-folders in the C:\Users\%username%\AppData\Local\Microsoft\Office\15.0\Lync folder and deletes the ABS__sipdomain.cache file which makes up the local Lync 2013 address book and the GAL*.* files that make up the local Lync 2010 address book.



@echo off
echo.
rem Check if Lync is running, exit if it is…
tasklist /fi “IMAGENAME eq lync.exe” | find “lync.exe” >nul
If %errorlevel%==0 goto LyncIsRunningError
rem Add x86 GALDownloadInitialDelay registry entry
reg add HKCU\Software\Policies\Microsoft\Communicator /v GALDownloadInitialDelay /t REG_DWORD /d 0 /f >nul
If %errorlevel%==1 goto ElevationError
rem Add WOW64 GALDownloadInitialDelay registry entry if x64
If %PROCESSOR_ARCHITECTURE%==AMD64 reg add HKCU\Software\Wow6432Node\Policies\Microsoft\Communicator /v GALDownloadInitialDelay /t REG_DWORD /d 0 /f >nul
If “%LOCALAPPDATA%”==”” Set LOCALAPPDATA=%USERPROFILE%\Local Settings\Application Data
dir “%LOCALAPPDATA%\Microsoft\Office\15.0\Lync\sip_*” /b > list.txt
FOR /F “tokens=1″ %%i in (list.txt) do (
rem Delete the Lync Server 2010 address book…
If Exist “%LOCALAPPDATA%\Microsoft\Office\15.0\Lync\%%i\gal*.*” del “%LOCALAPPDATA%\Microsoft\Office\15.0\Lync\%%i\gal*.*”
rem Delete the Lync Server 2013 address book…
If Exist “%LOCALAPPDATA%\Microsoft\Office\15.0\Lync\%%i\abs*.cache” del “%LOCALAPPDATA%\Microsoft\Office\15.0\Lync\%%i\abs*.cache”
)
del list.txt
echo Clearing Lync 2013 Address Books…  Done!
echo.
echo Sign back into Lync 2013 to download the current address book.
goto End
:ElevationError
echo ERROR: You must run this command from an elevated Command Prompt.
echo.
goto End
:LyncIsRunningError
echo ERROR: You must exit Lync 2013 before running this command. Right-click the Lync icon and choose Exit.
echo.
:End

Save the script above as UpdateLync2013AddressBook.bat.  Exit out of the Lync client and run the script from an elevated Command Prompt. Then sign back into Lync and the address book will download immediately.




Output from UpdateLync2013AddressBook.bat