If you have a password policy, you will need to import accounts using CSVDE as disabled. Then you must set the password of each account so that it meets your policy requirements. Only then can you enable the account.
This script will set the password, force it to be changed on next logon, and enable the account all in one shot. You feed it the DN column from your CSVDE spreadsheet.
Option Explicit
Dim strPW, intPW, intAccount
strPW = "password" 'Set your password here
intPW = 0 'Forces password change
intAccount = 512 'Enables account
'Script usage and confirmation
Dim strScriptName, i
strScriptName = "Account Enabler"
i = MsgBox ("Select a text file that has one user DN per line. The user will be enabled and their password will be set to " & strPW & ".", 1, strScriptName)
If i <> 1 Then
i = MsgBox ("Script aborted.", 0, strScriptName)
Wscript.Quit
End If
'Select the input file
Dim objCD, intCD, strCD
Set objCD = CreateObject("UserAccounts.CommonDialog")
objCD.Filter = "Text Documents|*.txt|All Files|*.*"
objCD.FilterIndex = 1
intCD = objCD.ShowOpen
If intCD = False Then
i = MsgBox ("No input file selected. Script aborted.", 0, strScriptName)
Wscript.Quit
End If
strCD = objCD.FileName
'Get user DNs from the input file
Dim arrDN
arrDN = GetLines(strCD)
'Perform action on each user
Dim strDN, objUser
For Each strDN in arrDN
Set objUser = GetObject("LDAP://" & strDN)
If objUser.class="user" then
objUser.SetPassword strPW
objUser.SetInfo
objUser.Put "pwdLastSet", intPW
objUser.SetInfo
objUser.Put "userAccountControl", intAccount
objUser.SetInfo
End If
Next
'Exit script
i = MsgBox ("Script done.", 0, strScriptName)
Function GetLines(strFile)
'Read file
Dim objTextFile, strText, objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(strFile, 1)
strText = objTextFile.ReadAll
objTextFile.Close
Set objTextFile = Nothing
'Trim trailing CR/LF from ini file
Dim intLength, strEnd
intLength = Len(strText)
strEnd = Right(strText, 2)
If strEnd = vbCrLf Then strText = Left(strText, intLength - 2)
'Write lines into array
Dim arrLines
arrLines = Split(strText, vbCrLf)
GetLines = arrLines
End Function
Until I come up with a standard disclaimer, just be warned that I am no programmer. Use my scripts only if you dare. Cheers!
No comments:
Post a Comment