본문 바로가기

IT Professional/Windows Management Technology

AD User Password reset script

'VBScript
'* description: create AD user accounts from the text file created by the export script.
'* author: Chris Pilling.
'* date: 18 June 2008.
'* I create an OU called import to create the accounts in then move the users around using dsa.msc.
'* REMEMBER to delete system generated accounts from the text file before running.
'* This script will quit if an account in the text file duplicates an existing one.
'* you will need to edit the FQDN for the UPN in the text file if your new AD is different from the
' one you exported from.  
on error resume next

Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
Const ADS_UF_NORMAL_ACCOUNT = 512 

Dim strL
Const ForReading = 1
Set objRoot = GetObject("LDAP://RootDSE")
varDomainNC = objRoot.Get("DefaultNamingContext")
Set objDomain = GetObject("LDAP://" & varDomainNC)
'* edit the line below to match your FQDN
'AP-Auth-Test.local
Set objOU = GetObject("LDAP://ou=wireless,dc=lginnotek,dc=com")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ts = objFSO.OpenTextFile("d:\script\emp_list.txt", ForReading)
Do until ts.AtEndOfStream
strL = ts.ReadLine
spl1 = Split(strL, ",")

'* edit the line below to match your FQDN
Set objOU = GetObject("LDAP://ou=wireless,dc=lginnotek,dc=com")
Set objUser = objOU.Create("User", "cn =" & (left(spl1(4),InStr(spl1(4),"@")-1)))

wscript.echo left(spl1(4))

    Set objUser = GetObject("LDAP://cn=" & (left(spl1(4),InStr(spl1(4),"@")-1)) & ",ou=wireless,dc=lginnotek,dc=com")
    objUser.SetPassword right(spl1(2),7)

objUser.AccountDisabled = FALSE
'* edit the password to suit
objUser.SetPassword(right(spl1(2),7))

intUAC = objUser.Get("userAccountControl")
    If ADS_UF_DONT_EXPIRE_PASSWD AND intUAC Then
            Wscript.Echo "Already enabled"
        Else
            objUser.Put "userAccountControl", intUAC XOR _
                ADS_UF_DONT_EXPIRE_PASSWD
            objUser.SetInfo
            WScript.Echo "Password never expires is now enabled"
    End If

wscript.echo  spl1(0) & spl1(1) & spl1(2) & spl1(3) & spl1(4)
wscript.echo  ((left(spl1(4),InStr(spl1(4),"@")-1))) & "," & (spl1(0)) & ","
wscript.echo "error code=" & Err.Number

Err.Clear
Loop