Re: need last logged on time for computer object, not user

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




<no@xxxxxxxx> wrote in message news:73Mwf.221$rS1.121@xxxxxxxxxxx
> yes... but that should have been made clear.

Well, it might have been made more clear, but...

- some people are offended by responses that imply they know less than they
know;
- giving too much detail in an answer is a waste of a person's time if it is
not necessary;
- you sometimes learn more by getting sparse hints and worrying at the
solution on your own.

> and it what format should this text file be? hostname only? fqdn? see
> my point? or should we just keep guessing??

Well, I had no idea you had those questions until you asked them. All you
need to do is ask (works better than complaining).

I would "guess" that it is the simple hostname. But there is no need to
guess - you could modify the code to emit a list of names deduced to be DC's
and see if that is in complete agreement with your list.

IMHO, though, it would be better to modify the script to extract a list of
DC's from the domain.

/Al

>
>
>
> "Al Dunbar" <AlanNOSPAmDrub@xxxxxxxxxxx> wrote in message
> news:%23URJr$ZFGHA.752@xxxxxxxxxxxxxxxxxxxxxxx
>>
>> "Jimmy D" <NOSPAM_jjd228@xxxxxxxxxxxxxxxxxxxx> wrote in message
>> news:OQuvUnWFGHA.1676@xxxxxxxxxxxxxxxxxxxxxxx
>>> what goes in DCFile?? you never explained anything
>>
>> On the contrary, the answer appears to be all there. You will get much
>> more from such an answer by working towards understanding it than ny
>> complaining.
>>
>> That said, it would appear that the strDCFile variable contains the name
>> of a text file, "C:\Domain_computers\DCList.txt", which contains a list
>> of domain controllers whose accounts are not to be deleted.
>>
>> /Al
>>
>>> "aaron" <aaron@xxxxxxxx> wrote in message
>>> news:O$9hhdWFGHA.3176@xxxxxxxxxxxxxxxxxxxxxxx
>>>> Const ForReading = 1
>>>> Const ForWriting = 2
>>>> Dim objFSO, objCompFile, objDCFile, objDomain, objComp, objNTComp
>>>> Dim strCompFile, strDCFile
>>>> Dim strDomain, strDCList
>>>> Dim intSecInADay, intAccountAge
>>>>
>>>> strCompFile = "C:\Domain_computers\InactivePCs.txt"
>>>> strDCFile = "C:\Domain_computers\DCList.txt"
>>>> strDomain = ""
>>>>
>>>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>>>> Set objCompFile = objFSO.OpenTextFile(strCompFile, ForWriting, TRUE)
>>>> Set objDCFile = objFSO.OpenTextFile(strDCFile, ForReading)
>>>> Set objDomain = GetObject("WinNT://" & strDomain)
>>>> objDomain.Filter = Array("Computer")
>>>> strDCList = objDCFile.ReadAll()
>>>> intSecInADay = 60 * 60 * 24
>>>> intAccountAge = 90
>>>>
>>>> For Each objComp In objDomain
>>>> Set objNTComp = GetObject("WinNT://" & strDomain & "/" &
>>>> objComp.Name & "$")
>>>> If (objNTComp.PasswordAge > intSecInADay * intAccountAge) Then
>>>> If InStr(1, strDCList, objComp.Name, vbTextCompare) = 0 Then
>>>> 'Call objDomain.Delete("Computer", objComp.Name)
>>>> objCompFile.Writeline objNTComp.Name & "-- computer account
>>>> has been deleted"
>>>> End If
>>>> End If
>>>> Next
>>>>
>>>>
>>>> --
>>>> aaron
>>>> A+,NET+,MCSE 2K/2K3,CNA,CCNA
>>>> "Jimmy D" <NOSPAM_jjd228@xxxxxxxxxxxxxxxxxxxx> wrote in message
>>>> news:Owo1oUWFGHA.2064@xxxxxxxxxxxxxxxxxxxxxxx
>>>>>i have the following script that gets me the last logged on time for
>>>>>all users in a 2000 domain. i need this to give me computers instead...
>>>>>we want to delete computer accounts that have been inactive for 30
>>>>>days. can anyone help? i tried but cant make it happen
>>>>>
>>>>> thank you!
>>>>> *********************************
>>>>>
>>>>>
>>>>> Option Explicit
>>>>>
>>>>> Dim objRootDSE, strConfig, objConnection, objCommand, strQuery
>>>>> Dim objRecordSet, objDC
>>>>> Dim strDNSDomain, objShell, lngBiasKey, lngBias, k, arrstrDCs()
>>>>> Dim strDN, dtmDate, objDate, lngDate, objList, strUser
>>>>> Dim strBase, strFilter, strAttributes
>>>>> Dim fso, output
>>>>>
>>>>> Set fso = CreateObject("Scripting.FileSystemObject")
>>>>> Set output = fso.OpenTextFile("c:\output.txt", 8, True)
>>>>>
>>>>> ' Use a dictionary object to track latest LastLogon for each user.
>>>>> Set objList = CreateObject("Scripting.Dictionary")
>>>>> objList.CompareMode = vbTextCompare
>>>>>
>>>>> ' Obtain local Time Zone bias from machine registry.
>>>>> Set objShell = CreateObject("Wscript.Shell")
>>>>> lngBiasKey = objShell.RegRead("HKLM\System\CurrentControlSet\Control\"
>>>>> _
>>>>> & "TimeZoneInformation\ActiveTimeBias")
>>>>> If UCase(TypeName(lngBiasKey)) = "LONG" Then
>>>>> lngBias = lngBiasKey
>>>>> ElseIf UCase(TypeName(lngBiasKey)) = "VARIANT()" Then
>>>>> lngBias = 0
>>>>> For k = 0 To UBound(lngBiasKey)
>>>>> lngBias = lngBias + (lngBiasKey(k) * 256^k)
>>>>> Next
>>>>> End If
>>>>>
>>>>> ' Determine configuration context and DNS domain from RootDSE object.
>>>>> Set objRootDSE = GetObject("LDAP://RootDSE";)
>>>>> strConfig = objRootDSE.Get("ConfigurationNamingContext")
>>>>> strDNSDomain = objRootDSE.Get("DefaultNamingContext")
>>>>>
>>>>> ' Use ADO to search Active Directory for ObjectClass nTDSDSA.
>>>>> ' This will identify all Domain Controllers.
>>>>> Set objCommand = CreateObject("ADODB.Command")
>>>>> Set objConnection = CreateObject("ADODB.Connection")
>>>>> objConnection.Provider = "ADsDSOObject"
>>>>> objConnection.Open "Active Directory Provider"
>>>>> objCommand.ActiveConnection = objConnection
>>>>>
>>>>> strBase = "<LDAP://"; & strConfig & ">"
>>>>> strFilter = "(ObjectClass=nTDSDSA)"
>>>>> strAttributes = "AdsPath"
>>>>> strQuery = strBase & ";" & strFilter & ";" & strAttributes &
>>>>> ";subtree"
>>>>>
>>>>> objCommand.CommandText = strQuery
>>>>> objCommand.Properties("Page Size") = 100
>>>>> objCommand.Properties("Timeout") = 60
>>>>> objCommand.Properties("Cache Results") = False
>>>>>
>>>>> Set objRecordSet = objCommand.Execute
>>>>>
>>>>> ' Enumerate parent objects of class nTDSDSA. Save Domain Controller
>>>>> ' AdsPaths in dynamic array arrstrDCs.
>>>>> k = 0
>>>>> Do Until objRecordSet.EOF
>>>>> Set objDC = _
>>>>> GetObject(GetObject(objRecordSet.Fields("AdsPath")).Parent)
>>>>> ReDim Preserve arrstrDCs(k)
>>>>> arrstrDCs(k) = objDC.DNSHostName
>>>>> k = k + 1
>>>>> objRecordSet.MoveNext
>>>>> Loop
>>>>>
>>>>> ' Retrieve LastLogon attribute for each user on each Domain
>>>>> Controller.
>>>>> For k = 0 To Ubound(arrstrDCs)
>>>>> strBase = "<LDAP://"; & arrstrDCs(k) & "/" & strDNSDomain & ">"
>>>>> strFilter = "(& (ObjectCategory=person)(ObjectClass=user))"
>>>>> 'strFilter = Array("computer")
>>>>> strAttributes = "DistinguishedName,LastLogon"
>>>>> strQuery = strBase & ";" & strFilter & ";" & strAttributes _
>>>>> & ";subtree"
>>>>> objCommand.CommandText = strQuery
>>>>> On Error Resume Next
>>>>> Err.Clear
>>>>> Set objRecordSet = objCommand.Execute
>>>>> If Err.Number <> 0 Then
>>>>> Err.Clear
>>>>> On Error GoTo 0
>>>>> Wscript.Echo "Domain Controller not available: " & arrstrDCs(k)
>>>>> Else
>>>>> On Error GoTo 0
>>>>> Do Until objRecordSet.EOF
>>>>> strDN = objRecordSet.Fields("DistinguishedName")
>>>>> lngDate = objRecordSet.Fields("LastLogon")
>>>>> On Error Resume Next
>>>>> Err.Clear
>>>>> Set objDate = lngDate
>>>>> If Err.Number <> 0 Then
>>>>> Err.Clear
>>>>> dtmDate = #1/1/1601#
>>>>> Else
>>>>> If (objDate.HighPart = 0) And (objDate.LowPart = 0 ) Then
>>>>> dtmDate = #1/1/1601#
>>>>> Else
>>>>> dtmDate = #1/1/1601# + (((objDate.HighPart * (2 ^ 32)) _
>>>>> + objDate.LowPart)/600000000 - lngBias)/1440
>>>>> End If
>>>>> End If
>>>>> On Error GoTo 0
>>>>> If objList.Exists(strDN) Then
>>>>> If dtmDate > objList(strDN) Then
>>>>> objList(strDN) = dtmDate
>>>>> End If
>>>>> Else
>>>>> objList.Add strDN, dtmDate
>>>>> End If
>>>>> objRecordSet.MoveNext
>>>>> Loop
>>>>> End If
>>>>> Next
>>>>>
>>>>> ' Output latest LastLogon date for each user.
>>>>> For Each strUser In objList
>>>>>
>>>>> output.WriteLine(strUser & " ; " & objList(strUser))
>>>>>
>>>>> 'Wscript.Echo strUser & " ; " & objList(strUser)
>>>>> Next
>>>>>
>>>>> ' Clean up.
>>>>> output.Close
>>>>> Set output = Nothing
>>>>> Set fso = Nothing
>>>>> Set objRootDSE = Nothing
>>>>> Set objConnection = Nothing
>>>>> Set objCommand = Nothing
>>>>> Set objRecordSet = Nothing
>>>>> Set objDC = Nothing
>>>>> Set objDate = Nothing
>>>>> Set objList = Nothing
>>>>> Set objShell = Nothing
>>>>>
>>>>> msgbox "done"
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>


.



Relevant Pages

  • Re: getting hostname from NT machine via Citrix
    ... "Tilman Bohn" wrote in message ... |>|> to get the hostname of the NT machine which is logging on. ... but getting the remote address & host through the Servlet API ... Programs that have duplicated logic are hard to modify. ...
    (comp.lang.java.help)
  • Re: Opening file too slow
    ... localhost ... csv610@blackhole:~$ hostname -f ... Modify settings or unsubscribe at: ...
    (Ubuntu)
  • Re: getting hostname from NT machine via Citrix
    ... "Tilman Bohn" wrote in message ... |> be accessible only via a login to Citrix from client machines. ... |> to get the hostname of the NT machine which is logging on. ... Programs that have duplicated logic are hard to modify. ...
    (comp.lang.java.help)
  • Re: Change hostname
    ... > I want to change the hostname from my server. ... > Which files i want modify? ... man sys-unconfig ...
    (comp.unix.solaris)
  • Re: DC for Exchange 2007
    ... You can modify the Configuration Domain Controller by right clicking ... either 'Organisation Configuration' or 'Server Configuration' within the EMC ... Site as the Domain Controllers you want them to use. ...
    (microsoft.public.exchange.admin)