Submitted By: Jarno Maki

Lists all the computers in Active Directory and the date and time their passwords were last changed.

Visual Basic
Edit|Remove
'
' *** Find all computers and list their last password change time ***
'
'     Written by Jarno Mäki / IT Education Center Finland
'     2005/04/18
'
'     NOTE!
'     Check out 'dsquery computer -inactive <number of weeks>'
'     (Dsquery requires Windows Server 2003 Forest)
'
On Error Resume Next

Set rs = CreateObject("ADODB.Recordset")
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

rs.Open "<LDAP://" & strDNSDomain & ">;(objectClass=computer);name,distinguishedName", "provider = ADsDSOObject"

strMachineList = ""

Do Until rs.EOF
	Set objComputer = GetObject("LDAP://" & rs.Fields("distinguishedName") & "")

	dtmValue = objComputer.PasswordLastChanged 
	dtmDiff = Datediff("d", dtmValue, Now)
		strLasttime = rs.Fields("Name") & " " & dtmDiff & vbCRLF
		strMachineList = strMachineList & strLasttime 
	  	rs.MoveNext
Loop

WScript.Echo strMachineList