Hi all,
I have this code that creates users. I want to display the current number of users that the program has read and I would like to increment the counter. This helps me see what user is giving me problems also. My problem is I don't know where to start the counter and I don't know where to increment it. I assume I need to put the code somewhere in the Do statement but I just don't know enough to get it done.
Any help would be greatly appreciated.
Thanks.
I have this code that creates users. I want to display the current number of users that the program has read and I would like to increment the counter. This helps me see what user is giving me problems also. My problem is I don't know where to start the counter and I don't know where to increment it. I assume I need to put the code somewhere in the Do statement but I just don't know enough to get it done.
Any help would be greatly appreciated.
Thanks.
Code:
Dim objFSO, objTextfile, user_arr, s
Const ForReading = 1
Const ADS_UF_ACCOUNTDISABLE = 2
Const ADS_PROPERTY_UPDATE = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextfile = objFSO.OpenTextFile("userlist.csv", ForReading)
Set objRootDSE = GetObject("LDAP://rootDSE")
strRootDomain = "LDAP://" & objRootDSE.Get("rootDomainNamingContext")
WScript.Echo "ADsPath to root domain container: " & strDomain
Set objRootDomain = GetObject(strRootDomain)
WScript.Echo "Current Domain Object:"
WScript.Echo "Name: " & objRootDomain.Name
WScript.Echo "Class: " & objRootDomain.Class & VbCrLf
Do while objTextfile.AtEndOfStream <> True
s = objTextfile.Readline
If instr(s, ",") Then
user_arr = split(s, ",")
wscript.Echo "====================================="
WScript.Echo VbCrLf
wscript.Echo "First Name: " & user_arr(0)
wscript.Echo "Initials: " & user_arr(1)
wscript.Echo "Last Name: " & user_arr(2)
wscript.Echo "Common Name: " & user_arr(3)
wscript.Echo "Password: " & user_arr(4)
wscript.Echo "sAMAccountName: " & user_arr(5)
wscript.Echo "UPN: " & user_arr(6)
wscript.Echo "OU: " & user_arr(7)
wscript.Echo "Group: " & user_arr(8)
WScript.Echo VbCrLf
Set objOU = GetObject("LDAP://ou=" & user_arr(7) & ",dc=test")
Set objUser = objOU.Create("User", "cn=" & user_arr(3) )
objUser.Put "givenName","" & user_arr(0)
objUser.Put "initials","" & user_arr(1)
objUser.Put "sn","" & user_arr(2)
objUser.Put "cn","" & user_arr(3)
objUser.Put "sAMAccountName","" & user_arr(5)
objUser.Put "userPrincipalName","" & user_arr(3)
objUser.SetInfo
objUser.SetPassword "" &user_arr(4)
objUser.SetInfo
intUAC = objUser.Get("userAccountControl")
If intUAC AND ADS_UF_ACCOUNTDISABLE Then
objUser.Put "userAccountControl", intUAC XOR ADS_UF_ACCOUNTDISABLE
objuser.Setinfo
Wscript.Echo "Account is now enabled"
WScript.Echo VbCrLf
wscript.Echo "====================================="
WScript.Echo VbCrLf
End If
Set objGroup = GetObject("LDAP://cn=" & user_arr(8) & ",ou=" & user_arr(7) & ",dc=test")
objGroup.PutEx ADS_PROPERTY_UPDATE, "member", Array("cn=" & user_arr(3) & ",ou=" & user_arr(7) & ",dc=test")
objGroup.SetInfo
Else
Wscript.Echo "Wrong File"
End If
Loop
objTextFile.Close