How can I be sure that there are always three digits as part of the Username number, i.e. ‘User-001’, 010, 100 and not ‘User-1′ or ’10’?
I’m also testing so that the script tells me how many accounts it created based out of the ‘i’ value but all I get is the stopping value, which is always one number more than what it’s actually created.
Thanks in advanced.
Here is my script:
‘::========================================================================
‘::ERROR CODES
‘::========================================================================
‘::800A01A8 OBJECT REQUIRED: ‘ ‘ Microsoft VBScript runtime error
‘::80070057 One or more arguments are invalid Active Directory
‘::8007007B The filename, directory name,or volumelabel syntax is incorrect. (null)
‘::========================================================================
Option Explicit
Dim strComputer, objComputer, strName, objUser
Dim strFullName, lngFlag, strPassword
Dim strNumberOfAccounts
DIM i
Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
‘ Specify local computer.
‘ This could also be retrieved from the wshNetwork object programmatically.
strComputer = “.”
i=0
‘ Bind to the local computer object.
Set objComputer = GetObject(“WinNT://” & strComputer)
‘ Specify local user name.
‘ Start ‘FOR’ loop.
strNumberOfAccounts = InputBox(“Enter number of accounts to create”)
for i = 1 to strNumberOfAccounts
strName = “ACCOUNT-”
‘ Create local user object.
Set objUser = objComputer.Create(“User”, strName & i) ‘ removing the ‘i’ will createthe account with an error message.
‘ Assign properties, like Full Name.
strFullName = “Sample Account”
objUser.Put “FullName”, strFullName
‘ Save the user object.
objUser.SetInfo
‘ Set password
strPassword = “USERPASSWORD”
objUser.SetPassword strPassword
‘ Set user flag so password never expires.
lngFlag = objUser.Get(“UserFlags”)
lngFlag = lngFlag Or ADS_UF_DONT_EXPIRE_PASSWD
objUser.Put “UserFlags”, lngFlag
‘ Save change.
objUser.SetInfo
NEXT
WScript.echo ” ‘” & strName & “‘ ” & i & “account was created successfully!”
‘::========================================================================