Here's an example of one way to do that. I would
suggest that if you're wanting to put in a random password that meets your
complexity requirements, that you concatenate a variable with the RAND function
and then write it back out to a log file. This example file is one
that was used in the test lab and could be more efficient. I had about
2500 users that I used and it took about a minute to execute.
Nonetheless, with minor mods, it should do what you want.
Let me know if I can be of any help (I'm bored
;)
Al
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Douglas M. Long
Sent: Monday, May 24, 2004 9:49 AM
To: [EMAIL PROTECTED]
Subject: RE: [ActiveDir] Password set and enable account
Oh
yeah, I guess I have to read the username from a file and pass it into the dsmod
command also. Do I just want a list of users in a .txt file, .cvs??? And how do
I read from that?
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of Douglas M. Long
Sent: Monday, May 24, 2004 9:41 AM
To: [EMAIL PROTECTED]
Subject: [ActiveDir] Password set and enable accountOk, so my task is to generate random passwords and enable the accounts for 3200 users. The user accounts and all attributes were first created with ldife, and I am now thinking about using the dsmod utility to do accomplish the password set and account enablement. I wish I knew vbs like you guys do, but I dont yet (this years resolution). So here is what I have for the password generation part:Function Password_GenPass( nNoChars, sValidChars )
' nNoChars = length of generated password
' sValidChars = valid characters. If zerolength-string ( "" )then
' default is used: A-Z AND a-z AND 0-9Const szDefault = "abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ0123456789"
Dim nCount
Dim sRet
Dim nNumber
Dim nLengthRandomize 'init randomIf sValidChars = "" Then
sValidChars = szDefault
End If
nLength = Len( sValidChars )For nCount = 1 To nNoChars
nNumber = Int((nLength * Rnd) + 1)
sRet = sRet & Mid( sValidChars, nNumber, 1 )
Next
Password_GenPass = sRet
End FunctionWScript.Echo "Your password: " & Password_GenPass( 10, "" )What is my next move? I am guessing I have to pass this password to a variable, instead of echo, and then somehow pass that into the dsmod command, but as I already said, I dont know vb script. Any help is highly appreciated.
'///// '///// ResetPasswordFromList.vbs '///// Written by Al Mulnick '///// BB&T Active Directory Services '///// '///// Script to reset passwords for accounts based on an input list of bnumbers (samaccount names) '///// '///// REV 1.0 5/2/2004 '///// '/////
'========================== Constructs ==========================
Const ForReading = 1, ForWriting = 2
'========================== End Constructs ======================
'========================== File Setup ==========================
Set fso = CreateObject("Scripting.FileSystemObject")
Set objFile = fso.OpenTextFile("UserPWDFix.Txt", ForReading) '<---//input file
Set objFileOut = fso.OpenTextFile("Out.txt", ForWriting,true) '<---//output file for
logging
'/////
'/////check to see that the source file exists. If not, exit
'/////
if err.number <> "0" then
wscript.echo err.number
wscript.echo "File Not Found!"
else
'========================== End File Setup ==========================
'========================== SCRIPT CONFIGURATION ==========================
strParentDN = "OU=Users,OU=Mortgage,DC=test-mtglms,DC=com"
'========================== End SCRIPT CONFIGURATION ======================
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
Do While Not objFile.AtEndOfStream '//Read till there are no more lines
strUser = trim(objFile.ReadLine)
'FindUserAD(strUser)
objCommand.CommandText = _
"<LDAP://" & strParentDN & ">;(&(objectCategory=User)" & _
"(samAccountName=" & strUser & "));ADsPath,distinguishedName;subtree"
Set objRecordSet = objCommand.Execute
If objRecordset.RecordCount = 0 Then
objFileOut.Writeline "ERROR: " & strUser & " does not exist."
Else
strDN = objRecordSet("distinguishedName")
Set objUser = GetObject("LDAP://" & strDN)
objUser.SetPassword strUser & "Password1."
objUser.AccountDisabled=FALSE
objUser.SetInfo
End if
Loop
End If
msgbox "Finished"
