Often, it can be a good idea to pre-populate Communicator (MOC) in an Office Communications Server 2007 R2 before end users start to use MOC. That way they’ll not be met with an “empty” contact list when they log on to MOC. For example, you might want to populate a user’s contact list with a group containing the members of the department the user belongs to. It’s rather easy to use LCSAddContacts.WSF to accomplish this, but I wanted to automate the process based on AD security groups, not only which OU the users/contacts belong to. I am doing all these commands from C:\Program Files\Microsoft Office Communications Server 2007 R2\ResKit\WMI Samples for simplicity.
- First, I need to list all the users in the AD Group containing the contacts, using the DN (Distinguished Name) of the group:
dsget group “CN=SomeGroup,OU=SomeOuAlso,OU=SomeOU,DC=domain,DC=com” -members -expand > members.txt
- Then, I need to get the msRTCSIP-PrimaryUserAddress for these contacts:
for /F “delims=” %x in (‘type members.txt’) do (dsquery * %x –l -attr msRTCSIP -PrimaryUserAddress >> contacts.txt)
Now I have a list over the contacts that should be populated into the contact list in MOC. The delims= is necessary to read the full lines also if there are spaces. The -l attribute is needed to get only the attribute, not also the name of the attribute for each line. If contacts.txt exists, make sure it’s empty at the script does not overwrite the file, but only appends new lines. - Now I need to get the users that should get these contacts:
dsget group “CN=SomeOtherGroup,OU=SomeOtherOU,OU=SomeOU,DC=domain,DC=com” -members -expand > userlist.txt
- Then, I need to get the msRTCSIP-PrimaryUserAddress for these users:
for /F “delims=” %x in (‘type userlist.txt’) do (dsquery * %x -l -attr msRTCSIP-PrimaryUserAddress >> users.txt)
- Let the magic happen:
cscript LCSAddContacts.WSF /usersfile:users.txt /contactsfile:contacts.txt /contactsgroup:”My group”
This would be a lot easier if the users and/or the contacts could be picked from a OU (or even manually enter the sip adresseses to users.txt or contacts.txt), but in a real-world scenario you might want to create MOC Contact groups based on AD groups.
Result:
P.S. Existing groups with the same same will not be overwritten, nor will existing contacts in that group. Only new contacts will be added.


