| |
Tetschko
Posts: 16
Score: 0
Joined: 7/18/2005
Status: offline
|
Hi! Now i´ve build a script, but my problem is that i cant get out the - when the password was set at (date and time) - the different between when the password was last set and today - when the password will expire date - in how many days form today the password will expire Please need help urgently ;-) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ On Error Resume Next Const ADS_SCOPE_SUBTREE = 5 Dim FileSystem 'Initialize global variables Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject") Set OutPutFile = FileSystem.CreateTextFile("user.txt", True) Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider" Set objCommand.ActiveConnection = objConnection objCommand.Properties("Page Size") = 1000 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE objCommand.CommandText = _ "SELECT DistinguishedName FROM 'LDAP://dc=nwtraders,dc=msftt' WHERE objectCategory='user'"_ ' & "AND userAccountControl='512'" Set objRecordSet = objCommand.Execute objRecordSet.MoveFirst Do Until objRecordSet.EOF ' OutPutFile.WriteLine objRecordSet.Fields("Name").Value ' OutPutFile.WriteLine objRecordSet.Fields("Name").Value objRecordSet.MoveNext Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000 Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D Const ONE_HUNDRED_NANOSECOND = .000000100 Const SECONDS_IN_DAY = 86400 Set objADSystemInfo = CreateObject("ADSystemInfo") ' LINE 8 'Set objUser = GetObject("LDAP://" & objADSystemInfo.UserName) ' LINE 9 OutPutFile.WriteLine objRecordSet.Fields("DistinguishedName").Value Set objUser = GetObject("LDAP://" & objADSystemInfo.objRecordSet.Fields("DistinguishedName").Value) ' LINE 9 intUserAccountControl = objUser.Get("userAccountControl") If intUserAccountControl And ADS_UF_DONT_EXPIRE_PASSWD Then OutPutFile.WriteLine "The password does not expire." WScript.Quit Else dtmValue = objUser.PasswordLastChanged If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then OutPutFile.WriteLine "The password has never been set." WScript.Quit Else intTimeInterval = Int(Now - dtmValue) OutPutFile.WriteLine "The password was last set on " & _ DateValue(dtmValue) & " at " & TimeValue(dtmValue) & vbCrLf & _ "The difference between when the password was last" & vbCrLf & _ "set and today is " & intTimeInterval & " days" End If Set objDomain = GetObject("LDAP://" & objADSystemInfo.DomainDNSName) Set objMaxPwdAge = objDomain.Get("maxPwdAge") If objMaxPwdAge.LowPart = 0 Then OutPutFile.WriteLine "The Maximum Password Age is set to 0 in the " & _ "domain. Therefore, the password does not expire." WScript.Quit Else dblMaxPwdNano = _ Abs(objMaxPwdAge.HighPart * 2^32 + objMaxPwdAge.LowPart) dblMaxPwdSecs = dblMaxPwdNano * ONE_HUNDRED_NANOSECOND dblMaxPwdDays = Int(dblMaxPwdSecs / SECONDS_IN_DAY) OutPutFile.WriteLine "Maximum password age is " & dblMaxPwdDays & " days" If intTimeInterval >= dblMaxPwdDays Then OutPutFile.WriteLine "The password has expired." Else OutPutFile.WriteLine "The password will expire on " & _ DateValue(dtmValue + dblMaxPwdDays) & " (" & _ Int((dtmValue + dblMaxPwdDays) - Now) & " days from today)." End If End If End If Loop ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The only data i get out are: CN=User,OU=1,DC=Nwtraders,DC=mssft Maximum password age is 90 days The password has expired Thanks for Help!!!! Regards T.
|
|