Thursday, January 8, 2009

Create Contact lists for all users with deparment as LDAP filter

I the real life when you have done all the OCS Infrastructure and integration, even run the first little Pilot and every thing is like it should be, you are ready to install Communicator to all the users in the company.

Remember the first thing that your users will see is this Communicator opens with no contacts at all, this is okay if it’s a former MSN users, they will quickly add contact, but what if it’s “New to IM” user, and they are still out there ;)
Do you think they will find this “Communicator” the most fantastic software in the world, with it’s white big empty area?
When a new employe is hired, it’s the same.

ocs_1_emty

What you need is a tool/script from the OCS Reskit called LCSAddContacts.wsf this script is for creating contact lists for your users.

I have created this little powershell script that will create files for LCSAddContacts.wsf based on a LDAP filter with Department as the key attribute.

**************

$currentdir = [System.IO.Path]::GetTemppath()
$datetime = Get-Date
$datetime = $datetime.ToString() -replace":","-"
$workdir = "$($currentdir)$($datetime)\"

if (!(Test-Path -path "$($workdir)"))
{New-Item "$($workdir)\" -type directory}

$strCategory = "person"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.Filter = ("(&(objectCategory=$strCategory)(Department=*)(msRTCSIP-PrimaryUserAddress=*))")

$colProplist = "department","msRTCSIP-PrimaryUserAddress"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}

$colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults)
{
$objtest = $objResult.Properties
$department = $objtest.department -replace",",""
$copyPath = "$($workdir)\$($department).txt"
if (!(Test-Path $copyPath)) {Write-output "c:\windows\system32\cscript LCSAddContacts.wsf /usersfile:""$($department).txt"" /contactsfile:""$($department).txt"" /contactsgroup:'My department' >>Contact-logfil.log" out-File "$($workdir)_CMD-$($datetime).txt" -append -encoding "ASCII"}
Write-output "$($objtest['msrtcsip-primaryuseraddress'])" out-File "$($workdir)\$($department).txt" -append -encoding "ASCII"
}

Write-output "notepad Contact-logfil.log" out-File "$($workdir)_CMD-$($datetime).txt" -append -encoding "ASCII"
$ShellExp = new-object -comObject Shell.Application
$ShellExp.open("$workdir")

***********************

It is a harmless powershell script, it will create files for you to review and dosen't do anything against your Activ Directory og OCS system, only reads from AD and write txt files to the disk.

When the script is finish there will be X numbers of files with department names as “filenames” and one command file called “_CMD-<Date-time>.txt, when you have reviewed this _CMD file and renamed it to .cmd there is no way back………if you execute it.
Take a look at it and test it in your lab first …………. then it’s on your own responsibility to use it in your production!
Or create your own :)
Remember to copy LCSAddContacts.wsf to the same folder as the .txt and CMD file

I am actualy not in favor of centrale controled contact lists, because they are meant as to be dynamic, and there is diffrent needs from user to user, but as a “one time shot” when you have enabled all your users or for newly hired user, I think it could be a good idee to create contact lists.
Or if you have some general contacts like IT support.

Please remember to create only lists with max 20-30 uses in, because the default MAX number of contacts on the server-side is 150. and if you have more than 30 contact in one single lists I think it’s to many, and again it diffrent needs from users to users.

In R2 this script will also work, and the Mobile Communicator R2 will first get the presence status on your contacts when you expand your Contact groups, it's taking some time to expand this gruops and if you have more that 30 contact it's taking even longer.