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


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”)


Header=fl.ReadLine


arHdr=split(Header,”,”)


Header=””


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


lDapPath=”OU=UC,dc=ucdom,dc=local”


for i=0 to ubound(arHdr)


Header=Header & arHdr(i) & vbTab


next


wscript.echo Header


Set objOU = GetObject(“LDAP://” & lDapPath)


on error resume next


while fl.AtEndOfStream=False


errorsOccured=0 ‘no errors


userLine=fl.ReadLine


arUser=split(userLine,”,”)


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)


objUser.SetInfo


if err.number <> 0 then


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


errorsOccured=1 ‘errors occured


err.clear


end if


objUser.SetPassword “Password@123” 


objUser.accountDisabled=FALSE


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


objUser.SetInfo


if err.number <> 0 then


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


errorsOccured=1 ‘errors occured


err.clear


end if


if errorsOccured=0 then


wscript.echo userLine & “…Processed.”


else


wscript.echo userLine & “…Processing…”


end if


err.clear ‘clear last error.


wend


fl.close


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..


lDapPath=”OU=UC,dc=ucdom,dc=local”


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.


 


 


Comments (67)

  1. Premkumar Yogeswaran says:

    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,

    Prem

  2. Ram Ojha says:

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

    Regards,

    Ram

  3. Zizebra says:

    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.

  4. http://www.iessaywriter.com says:

    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

  5. Clash of Clans for PC says:

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

  6. WeChat Messenger for PC says:

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

  7. Clash of Clans for Computer says:

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

  8. WhatsApp Messenger on Computer says:

    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/

  9. iOS 9 Release Date says:

    I am early waiting for the iOS 9 release date and iPhone 7 release date:
    http://www.ios9releasedate.com

  10. Whatsapp says:

    Thanks for such a share.Well I would also like to share something with you guys

    http://www.whatsappforpcpro.com/

  11. iMessage says:

    Hey giys I just found out a new way through which you can get imessage on Android and you can check that out here

    http://www.getappsonpc.com/imessage-for-android-phone-apk-download/

  12. Packers and Movers Pune says:

    Thanks for all your information, Website is very nice and informative content.
    If you are looking Best Packers and Movers so Visit at :
    http://www.smaart5th.in/packers-and-movers-in-navimumbai/
    http://www.smaart5th.in/packers-and-movers-in-thane/
    http://www.smaart5th.in/packers-and-movers-in-noida/
    http://www.smaart5th.in/

  13. Packers and movers Pune says:

    This article is really fantastic and thanks for sharing the valuable post.
    http://www.expert5th.in/packers-and-movers-pune/
    http://packersmoverspune.top3rd.in/

  14. Packers says:

    This article is really fantastic and thanks for sharing the valuable post.
    http://packersmoverspune.top3rd.in/

  15. Packers says:

    This article is really fantastic and thanks for sharing the valuable post.
    http://www.expert5th.in/packers-and-movers-pune/

  16. INSTAGRAM says:

    I really enjoyed & liked everything.
    Thanks for sharing informative post ……..

    REF: http://quickfansandlikes.com/

  17. Rahul Yadav says:

    This is something with which I am totally agreed for sure.. Loved the way now we can play candy crush on PC. check full guide here
    http://droidadda.com/play-candy-crush-for-pc/ .. Thanks

  18. Dhruv says:

    Wow. Thanks for sharing. I like this article.
    http://pancardstatusin.com

  19. Saurabh says:

    https://medium.com/@adarshshah/how-to-apply-and-track-pan-status-in-india-cc1b5862112
    http://adarsh27.kinja.com/what-is-pan-card-status-how-to-get-it-1714608633
    http://www.instructables.com/id/What-is-PAN-Card/
    http://pancard.snack.ws/
    http://adarshgm2.inube.com/blog/4402173/how-to-get-pan-card-or-duplicate-pan-card-status-without-acknowledge-no/
    http://appsforpc.india.com/post/know-your-pan-card-status-by-name-online-40407

    http://www.communitychannel.org/your-community-space/ycs-blogs/55b3707690eaf/
    http://www.kiwibox.com/adarshgm2/blog/entry/131710569/get-online-pan-card-status-here/?pPage=0
    https://www.rebelmouse.com/adarshgm2/how-to-apply-online-for-adhaar-card-1268025030.html
    http://www.imfaceplate.com/adarshgm2/how-to-know-your-pan-card-status-online
    http://indyarocks.com/blog/2375804/Know-Your-Pan-Card-Status-Here
    http://technology.zumvu.com/track-your-pan-card-status-here
    http://adarshgm2.buzznet.com/user/journal/26492926/verify-pan-card-status-here/

    http://justpaste.it/PANcardstatus
    http://pancardstatus.jimdo.com/
    http://adarshgm2.postbit.com/how-to-apply-for-new-pan-card-online.html
    http://adarshgm2.mywapblog.com/see-your-pan-card-status-without-acknowl.xhtml
    https://www.smore.com/upgkk-why-adhaar-card-is-necessary

    https://entertainment27.edublogs.org/2015/08/04/how-to-get-adhaar-card-status-online/
    http://pan-card-status.webnode.com/news/documents-required-for-aadhaar-card-enrollment/
    http://www.merchantcircle.com/blogs/seo.456-456-4561/2015/8/Get-Pan-Card-Status-Here/1275979

    http://www.purevolume.com/dashboard?s=posts&tab=posts
    http://keralalotteryresult.sportsblog.com/posts/2975160/get-print-of-your-adhaar-card.html
    http://technology1.doomby.com/blog/get-your-aadhaar-card-status-on-mobile.html
    http://adarshgm2.blog.com/2015/08/05/requirements-to-verify-pan-card-status/

    http://writers.sportskeeda.com/?p=2402240&preview=true
    http://www.mediamatic.net/399751/en/how-to-get-e-adhaar-card-download
    http://uchem.berkeley.edu/forum/read.php?3,1632078,1632078#msg-1632078
    http://www.buzzfeed.com/post?id=3928570
    http://pancardstatus.samenblog.com/How%20to%20Get%20status%20of%20My%20Adhaar%20Card%20Online/
    https://unisa-au.academia.edu/AdarshShah/Posts/5791103/Reprint-your-Adhaar-Card-online-Adhaar-Card-is-a-government-authorized-free-procedure-in-which-every
    http://community.eldis.org/adarshgm2/.5c5dc7a9/.5c5dc7d6
    http://adarshgm2.tumblr.com/post/126319805481/get-status-of-your-pan-card-without-knowing
    http://adarshgm2.bcz.com/2015/08/10/go-online-to-check-your-pan-card-status/
    http://www.twitlonger.com/show/n_1sn8d75
    https://storify.com/adarshgm2/check-online-pan-card-status-here#publicize
    http://pancardstatus.weebly.com/
    https://adarshgm2.wordpress.com/2015/08/13/uidai-e-aadhaar-card-download/
    https://moz.com/posts/manage
    http://pancardstatus.unblog.fr/2015/08/21/get-pan-card-status-online-free-guidelines/
    http://entertainments.hatenablog.com/entry/2015/08/21/153852
    http://informations.wallinside.com/
    http://pancardstatus.zohosites.com/blogs/post/Watch-Pan-Card-Status-Online

  20. instagram says:

    Anyone is familiar with which social network sites could be the brand spanking new locations to market every little thing. Numerous Instagram admirers imply plenty of people see in addition to price your personal images. Several companies monitor this
    kind of like a new technique to market.
    http://whohah.com/

    http://morefollowersonline.com/

    http://morefollowersonline.com/buy-instagram-likes.html

    http://morefollowersonline.com/buy-instagram-followers.html

  21. WeChat for PC says:

    Here is a perfect guide to get WeChat messenger for PC
    http://wechatforpcworld.com/

  22. Jassie Pinkman says:

    i think this problem is related to Windows. Try using windows 8 product key
    source: http://www.tech1up.com

  23. Pankaj Kumar says:

    Thanks for sharing this useful guide….

    http://www.rushinformation.com

  24. Game of War for PC says:

    Thanks for this wonderful share. Now Download Game of War for PC at
    http://www.gameofwarforpc.com

  25. 3D Coloring Pages says:

    Augmented reality based 3D coloring pages let kids see and play with their colored character in 3D . 3D coloring books opens a whole new dimension in kids education. Visit now @
    http://www.3dcoloringpages.com

  26. raj says:

    check your http://gateresult2016.co.in/ avaliable here

  27. aranyak says:

    awesome stuff.. keep it up.. http://bluedartcustomercares.com/

  28. dazy saloman says:

    For trusted Packers and Movers Visit:-
    http://www.movers5th.in/packers-and-movers-hyderabad/
    For faithful Packers and Movers Visit:-
    http://www.movers5th.in/packers-and-movers-bangalore/
    For verified Packers and Movers visit:-
    http://www.movers5th.in/packers-and-movers-pune/