Share via


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