' Determine DNS domain name from RootDSE object. Set objRootDSE = GetObject("LDAP://RootDSE") strDNSDomain = objRootDSE.Get("defaultNamingContext")
' Use the NameTranslate object to find the NetBIOS domain name from the ' DNS domain name. Set objTrans = CreateObject("NameTranslate") objTrans.Init ADS_NAME_INITTYPE_GC, "" objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4) ' Remove trailing backslash. strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)
' Use the NameTranslate object to convert the NT user name to the ' Distinguished Name required for the LDAP provider. OnErrorResumeNext objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strUserNTName If (Err.Number <> 0) Then OnErrorGoTo0 Wscript.Echo "User " & strUserNTName _ & " not found in Active Directory" Wscript.Echo "Program aborted" Wscript.Quit EndIf strUserDN = objTrans.Get(ADS_NAME_TYPE_1779) ' Escape any forward slash characters, "/", with the backslash ' escape character. All other characters that should be escaped are. strUserDN = Replace(strUserDN, "/", "\/")
' Bind to the user object in Active Directory with the LDAP provider. OnErrorResumeNext Set objUser = GetObject("LDAP://" & strUserDN) If (Err.Number <> 0) Then OnErrorGoTo0 Wscript.Echo "User " & strUserNTName _ & " not found in Active Directory" Wscript.Echo "Program aborted" Wscript.Quit EndIf objUser.SetPassword strPassword If (Err.Number <> 0) Then OnErrorGoTo0 Wscript.Echo "Password NOT reset for " &vbCrLf & strUserNTName Wscript.Echo "Password " & strPassword & " may not be allowed, or" Wscript.Echo "this client may not support a SSL connection." Wscript.Echo "Program aborted" Wscript.Quit Else objUser.AccountDisabled = False objUser.Put "pwdLastSet", 0 Err.Clear objUser.SetInfo If (Err.Number <> 0) Then OnErrorGoTo0 Wscript.Echo "Password reset for " & strUserNTName Wscript.Echo "But, unable to enable account or expire password" Wscript.Quit EndIf EndIf OnErrorGoTo0
Wscript.Echo "Password reset, account enabled," Wscript.Echo "and password expired for user " & strUserNTNamegetting