VB Script


hi all,

i need help.

i need import users in test dc(because of particular attributes). import user , reset password well. script need excel sheet contains user information , have on same location.

i working on 1 script result not coming per expectation.

below mention script. can body in this.

on error resume next

dim objxl, objuser, objou, objargs
dim stradspath, strroot, strou, strusername, strxl
dim crlf

set objargs=wscript.arguments
strou = ""

crlf = chr(13) & chr(10)
 
if objargs.count = 0 then
     strxl = inputbox("this scripts reads excel spreadsheet , adds" & _
     "users directory service via adsi." & crlf & crlf & _
     "before starting, change ds root in excel spreadsheet match " & _
     "your ds." & crlf & crlf & _
     "type in path of file containing users add or delete" & crlf & crlf & _
     "sample add user file: c:\addusers.xls" & crlf & _
     "sample delete user file: c:\delusers.xls" & crlf)
     else
     strxl = objargs.item(0)
end if

if strxl = "" then
     msgbox "you must provide excel spreadsheet script run.", vbcritical + 4096, "file empty"
     wscript.quit(1)
end if
set objxl = wscript.createobject("excel.application")
objxl.visible = true
objxl.workbooks.open strxl
objxl.sheets("add").activate
objxl.activesheet.range("a2").activate ' cell has ds root in it
'wscript.echo  objxl.activecell.value
strroot = objxl.activecell.value
objxl.activecell.offset(1, 0).activate

do while objxl.activecell.value <> ""
     if objxl.activecell.value <> strou then
          strou = objxl.activecell.value
          stradspath = "ldap://ou=accounts,dc=stargate,dc=com" & strou+"," & strroot
             wscript.echo stradspath
          set objou = getobject(stradspath)
     end if
     strusername = "cn=" + objxl.activecell.offset(0, 1).value + "." + objxl.activecell.offset(0, 2).value
     set objuser = objou.create("user", strusername)
     objuser.put "givenname", objxl.activecell.offset(0, 1).value 'givenname
     objuser.put "sn", objxl.activecell.offset(0, 2).value 'sn
     objuser.put "mail", objxl.activecell.offset(0, 3).value 'email
        objuser.put "userprincipalname", objxl.activecell.offset(0, 3).value 'upn
     objuser.put "samaccountname", objxl.activecell.offset(0, 4).value  'sam acct
     objuser.put "telephonenumber", objxl.activecell.offset(0, 5).value  'phone
        objuser.put "displayname", objxl.activecell.offset(0, 6).value  'display name
        objuser.put "description", objxl.activecell.offset(0,8).value 'job title
        objuser.put "title", objxl.activecell.offset(0,7).value 'rank
        objuser.put "department", objxl.activecell.offset(0,10).value 'section
        objuser.put "company", objxl.activecell.offset(0,9) 'unit
        objuser.setpassword "password","password123"
        objuser.setinfo
       
        objuser.accountdisabled=false 
     objuser.setinfo
     set objuser = nothing
objxl.activecell.offset(1, 0).activate   'next row
loop
objxl.application.quit

 thanks

amit

please post scripting related questions in scripting guys forum:

http://social.technet.microsoft.com/forums/en/itcg/threads


santhosh sivarajan | houston, tx
http://www.sivarajan.com/

facebook twitter linkedin ss tech forum

posting provided no warranties,and confers no rights.



Windows Server  >  Directory Services



Comments

Popular posts from this blog

WIMMount (HSM) causing cluster storage to go redirected (2012r2 DC)

Failed to delete the test record dcdiag-test-record in zone test.com

Azure MFA with Azure AD and RDS