Automatically Build the Contact List for OCS Users
To automatically build and update your users OCS contact lists with new contacts, you need to go back to your scripting skills and use something similar to the following.
@ECHO GET ALL USERS
dsquery * "OU=Staff,OU=User Accounts,DC=domain,DC=local" -attr msRTCSIP-PrimaryUserAddress -filter "(msRTCSIP-UserEnabled=TRUE)" > allusers.txt
type allusers.txt | find "sip:" > allusers2.txt
@ECHO Executive
dsquery * "OU=Executive,OU=Staff,OU=User Accounts,DC=domain,DC=local" -attr msRTCSIP-PrimaryUserAddress -filter "(msRTCSIP-UserEnabled=TRUE)" > exec.txt
type exec.txt | find "sip:" > exec2.txt
@ECHO HR,Finance & Admin
dsquery * "OU=HR\, Finance & Admin,OU=Staff,OU=User Accounts,DC=domain,DC=local" -attr msRTCSIP-PrimaryUserAddress -filter "(msRTCSIP-UserEnabled=TRUE)" > fin.txt
type fin.txt | find "sip:" > fin2.txt
@ECHO SALES & MARKETING
dsquery * "OU=Sales & Marketing,OU=Staff,OU=User Accounts,DC=domain,DC=local" -attr msRTCSIP-PrimaryUserAddress -filter "(msRTCSIP-UserEnabled=TRUE)" > sales.txt
type sales.txt | find "sip:" > sales2.txt
@ECHO Clear Contact Lists
cscript LCSAddContacts.wsf /usersfile:allusers2.txt /contactsfile:exec2.txt /delete
cscript LCSAddContacts.wsf /usersfile:allusers2.txt /contactsfile:fin2.txt /delete
cscript LCSAddContacts.wsf /usersfile:allusers2.txt /contactsfile:sales2.txt /delete
@ECHO BUILD Contact Lists
cscript LCSAddContacts.wsf /usersfile:allusers2.txt /contactsfile:exec2.txt /contactsgroup:Executive
cscript LCSAddContacts.wsf /usersfile:allusers2.txt /contactsfile:fin2.txt /contactsgroup:"HR, Finance & Admin"
cscript LCSAddContacts.wsf /usersfile:allusers2.txt /contactsfile:sales2.txt /contactsgroup:"Sales & Marketing"
How does it work? The First three lines query active directory for all users in the "Staff" OU, and then filter them by those that are enabled for OCS. The output is then redirected to the "allusers.txt" file. The next line is used to filter out just the users in the form sip:email.address@domain.com to a new text file.
The next few blocks of text use the same method however the OU path is different for each one, and so is the output txt files. By doing this we can then import different users into different groups within the OCS contact list.
Once the script reaches the "Clear Contact Lists", it is now flushing out all the contacts from the users contact list. We do this so that any users who had previously been disabled from OCS for various reasons are removed. The LCSAddContacts.wsf file is part of the OCS Resource Kit, available here: http://www.microsoft.com/downloads/details.aspx?FamilyID=b9bf4f71-fb0b-4de9-962f-c56b70a8aecd&displaylang=en
The LCSAddContacts.wsf uses the allusers2.txt to determine which OCS users the contact list will be deleted or created/added to. It then uses the filtered OU user txt files to add the contacts to their respective groups as determined by the "/contactsgroup:xxxx" flag.
You can use any method you like to build the txt files, for example you could use dsget to build the lists based on AD groups:
dsget group “CN=SomeGroup,OU=SomeOuAlso,OU=SomeOU,DC=domain,DC=com” -members -expand > members.txt
for /F “delims=” %x in (‘type members.txt’) do (dsquery * %x –l -attr msRTCSIP -PrimaryUserAddress >> contacts.txt)
To automate the process, save your script as a .bat and then use a windows scheduled task to run it automatically for you.




