Enable an OCS User using a VBScript

OCS Script: Here's a simple VBScript that enables an OCS (Office Communication Server) user in Active Directory. I realize that Perl isn't everyone's favorite scripting language, so I'm putting some examples together in other languages. It looks like OCS scripting is the most popular topic I've covered so far, so here's my first OCS script written in VBScript.

The script uses ADO to search for the user (whose common name or sAMAccountName matches the user variable), and configures the user's OCS properties. Notice in the first few lines of the script, I hard code the distinguished name of the meeting policy and the OCS pool. You can find out the distinguished names of your OCS pools and policies using the scripts in my other post: List OCS Pools and Policies Using a VBScript.

'set the OCS pool and meeting policy that you want applied to the user
meetingPolicy="CN={BA9AD4FA-3516-47BD-A2C2-4556AE4D7263},CN=Policies,CN=RTC Service,CN=Services,CN=Configuration,DC=myDomain,DC=com"
pol1="B:8:01000000:" & meetingPolicy
homeServerDN = "CN=LC Services,CN=Microsoft,CN=OCSPOOL01,CN=Pools,CN=RTC Service,CN=Services,CN=Configuration,DC=myDomain,DC=com"
'build an ADO connection to Active Directory
set dse = GetObject("LDAP://RootDSE")
root = dse.Get("RootDomainNamingContext")
adpath = "GC://" & root
base = "<" & adpath & ">"
Set conn = CreateObject("ADODB.Connection")
Set comm = CreateObject("ADODB.Command")
conn.Provider = "ADsDSOObject"
conn.Open "Active Directory Provider"
Set comm.ActiveConnection = conn
comm.Properties("Page Size") = 1000
'search for the user
comm.CommandText = base & ";(&(objectCategory=User)((cn=" & user & ")(sAMAccountName=" & user &")));displayName,distinguishedName;subtree"
Set rs = comm.Execute
Do Until rs.EOF
 displayName = rs.Fields(0).Value
 dn = rs.Fields(1).Value
 Set userObj = GetObject("LDAP://" & dn)
 Wscript.Echo "Enabling " & userObj.givenName & " " & userObj.sn & " for OCS"
 userMail = userObj.mail
'set the OCS properties of the user
 userObj.Put "msRTCSIP-ArchivingEnabled", 0
 userObj.Put "msRTCSIP-FederationEnabled", TRUE
 userObj.Put "msRTCSIP-OptionFlags", 256
 userObj.Put "msRTCSIP-PrimaryHomeServer", homeServerDN
 userObj.Put "msRTCSIP-PrimaryUserAddress", "sip:" & userMail
 userObj.Put "msRTCSIP-UserEnabled", TRUE
 userObj.Put "msRTCSIP-UserPolicy",pol1


Anonymous said...

Thanks for this Brian. The Perl version was not helping me!

Brian Seltzer said...

Yeah sorry, Perl is my first language. I'm working to add versions of my scripts in other languages as I get the time...

Lentin Varghese said...


first of all thanks for the post. I am just new to wmi scripting ..may be because of that this script is not working for me. can u pls tell me wer should i make changes in the script other than meeting policy and home server DN. i already taken both these things manully using adsiedit. ur answer is very important for me as there is no other option to add newely added AD user to OCS server.


Brian Seltzer said...

Hi Lentin,

For the script to work, you just need to change the: user, meetingPolicy, and homeServerDN

The user variable must be set to the cn or the samAccountName of the user you are trying to set. Also, the user must have a mail address set (which is used to form the user's SIP address. Please let me know how you make out.


Kelly C said...

Brian how can I modify this script to only add the PrimaryHomeServer property to each user?

We are migrating users and everything migrates without a problem except the msRTCSIP-PrimaryHomeServer attribute is blank. Even though in the target domain it has the correct OCS pool DN


Brian said...

Hi Kelly,

Assuming everything else is set correctly, you can simply remark out the other userObj.Put lines in the script except for the homeserver line, like so:

'set the OCS properties of the user
'userObj.Put "msRTCSIP-ArchivingEnabled", 0
'userObj.Put "msRTCSIP-FederationEnabled", TRUE
'userObj.Put "msRTCSIP-OptionFlags", 256
userObj.Put "msRTCSIP-PrimaryHomeServer", homeServerDN
'userObj.Put "msRTCSIP-UserEnabled", TRUE
'userObj.Put "msRTCSIP-UserPolicy",pol1

Hope that helps!

Post a Comment

Related Posts Plugin for WordPress, Blogger...