Ram Ojha's Blog

Unfied Communications Diary...

Script - to create users in AD and enable it for Office Communications server

Script - to create users in AD and enable it for Office Communications server

  • Comments 10
  • Likes

I wrote a simple script to automate the process of user account creation in AD and to enable them for OCS with EV, which I am sharing at this blog... Before I start talking about the script further, I'd request everyone to read the following disclaimer carefully.

Disclaimer: Run the script in your environment at your own risk. This script re-writes proxyAddresses, so modify the script to have proper proxyAddresses value if you have Exchange setup. Please don’t run this script in production at any cost without testing it in your test environment, and without further modifying it to suit your requirements.

About the script: This script takes a CSV file as an input with following parameters of the user...

Display Name, SAMAccountName, UserPrincipalName, TelephoneNumber, Description, SIP Address.


iput file 


The script will do followings…

·         It will create the user.

·         It’ll read display name from the file and write FirstName, LastName and DisplayName of the user.

·         It’ll set the TelephoneNumber of the user.

·         It’ll enable the user for Office Communications server

·         It’ll set the SIP address (msRTCSIP-PrimaryUserAddress)

·         It’ll assign the user to a pool (msRTCSIP-PrimaryHomeServer)

·         It’ll enable the user for Enterprise Voice (msRTCSIP-OptionFlags)

·         It’ll assign the Line URI (msRTCSIP-Line)


Steps to run the script:

Step 1:

Copy the following script and save it as “createNenableUsers.vbs”.



dim Header,FileName,fs,fl,objOU

set fs=CreateObject("Scripting.FileSystemObject")

set fl=fs.OpenTextFile("C:\scripts\User_Accounts-ADS-CSV.csv")




' DN of the OU where USers are supposed to be created


for i=0 to ubound(arHdr)

Header=Header & arHdr(i) & vbTab


wscript.echo Header

Set objOU = GetObject("LDAP://" & lDapPath)

on error resume next

while fl.AtEndOfStream=False

errorsOccured=0 'no errors



Set objUser = objOU.Create("User", "cn=" & arUser(0))

'assuming that fields in CSV files are: CN,sAMAccountName,UserPrincipalName,Telephone Number,Description

'Generate firstname(givenName),lastname(sn),displayname (displayname)

arUinfo=split(arUser(0)," ")

objUser.Put "givenName",arUinfo(0)

objUser.Put "sn",arUinfo(1)

objUser.Put "displayName",arUser(0)

objUser.Put "sAMAccountName",arUser(1)

objUser.Put "UserPrincipalName",arUser(2)

objUser.Put "telephoneNumber",arUser(3)

objUser.Put "description",arUser(4)

objUser.Put "msRTCSIP-PrimaryUserAddress",arUser(5)

objUser.Put "proxyAddresses",arUser(5)

objUser.Put "msRTCSIP-Line","Tel:+" & arUser(3)


if err.number <> 0 then

wscript.echo "[Error] processing user: [" & arUser(0) & "] " & err.description

errorsOccured=1 'errors occured


end if

objUser.SetPassword "Password@123" 


objUser.put "msRTCSIP-UserEnabled",TRUE

objUser.Put "pwdLastSet", 0

objUser.Put "msRTCSIP-PrimaryHomeServer","CN=LC Services,CN=Microsoft,CN=UCOCSR2,CN=Pools,CN=RTC Service,CN=Services,CN=Configuration,DC=ucdom,DC=local"

objUser.Put "msRTCSIP-OptionFlags",384


if err.number <> 0 then

wscript.echo "[Error] processing user password/account settings: [" & arUser(0) & "] " & err.description

errorsOccured=1 'errors occured


end if

if errorsOccured=0 then

wscript.echo userLine & "...Processed."


wscript.echo userLine & "...Processing..."

end if

err.clear 'clear last error.



set fs=nothing



Step 2: Modify location of the input file…

set fl=fs.OpenTextFile("C:\scripts\User_Accounts-ADS-CSV.csv")

Step 3: Modify the LDAP path, where you want to create the users..


Step 4: Modify the following line to set the default password…

objUser.SetPassword "Password@123"

Step 5: change the Pool DN

objUser.Put "msRTCSIP-PrimaryHomeServer","CN=LC Services,CN=Microsoft,CN=UCOCSR2,CN=Pools,CN=RTC Service,CN=Services,CN=Configuration,DC=ucdom,DC=local"

Step 6: After modifying the script as per your setup… run the following command...

Cscript  createNenableUsers.vbs

Note: You should run the command from a location where this script is located.


I am sure you would need to modify the script as per your need, if you encounter any problem while doing it... Leave a comment and if time permits, I’ll respond with a reply.



  • Hi,

    Please clear my doubt.

    Does this script to be run in Communication Server or we can run the script in any DC in the domain.

    If i run the script in any other domain does this SIP will enable in communication server?

    Thanking you in advance,


  • You can run this script from any machine in the domain.



  • I recently wrote a script more like yours, however after all settings have been committed, and I can verify that in AD, OCS does not seem to recognise that the user is indeed enabled for OCS and voice unless I open the users and click ok instead of cancel.

  • As nice blog,but you could have made this blog more cool if you could configure the language changer pluigin but all the same you have done http://www.iessaywriter.com">http://www.iessaywriter.com a good job

  • Thanks for this super amazing posts. http://www.isubwaysurfersforpc.com/subway-surfers-for-pc-free-download-windows.html

  • I think when you are doing the things possible then its Clash of Clans for PC http://clashofclansforpcc.com

  • We have working guide for downloading WeChat on Computer http://www.wechatforpcr.com

  • I want to tell you that its really possible to enjoy downloading Clash of Clans on Computer http://clashofclanspcworld.com

  • So folks, you want to download WhatsApp Messenger on PC check this out : http://www.whatsappforpcmi.com/whatsapp-for-pc-download-windows-7-8-computer-laptop/

  • I am early waiting for the iOS 9 release date and iPhone 7 release date:

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment