Listar los Domain controllers de un dominio

$dcObj = [adsi]"LDAP://OU=domain controllers,dc=ar,dc=lugsaju,dc=com"
$dcs = $dcObj.PSBase.Children | % { $_.name }
$cantDCs = $dcs.count
$contDC = 0
foreach ($dc in $dcs){
$a = ping -n 1 $dc
$a = $(($a[2]).split("[")[1]).split("]")[0]
write-output "$dc`t$a"
}

con la ip de bonus track

función para nombrar archivos de log - vbscript

Function NomArch(NomArch)    ' Para nombrar los archivos.
Dim arch,hoy,aa,mm,dd
hoy = Date
aa = year(hoy)
mm = month(hoy)
dd = day(hoy)
arch = aa & "_0" & mm & "_" & dd & "_" & NomArch & ".log" ' Formato: \AAAA_MM_DD_NomArch.log
NomArch = arch
End Function

' uso
Set objFS = CreateObject("Scripting.FileSystemObject")
carpeta = "C:\logs"
ArchLogGen = "LogGeneral"
NomLog = NomArch(strArchLogGen)
Set logArchLogGen = objFS.OpenTextFile(carpeta & NomLog, 8,TRUE)

objFS.Close

Ultimo logon de usuario

Creditos a Richard Mueller por el script, posteado originalmente aqui.
He modificado la propiedad LastLogon por LastLogonTimeStamp, valor que SI se replica entre DCs.



Option Explicit

Dim objRootDSE, adoConnection, adoCommand, strQuery
Dim adoRecordset, strDNSDomain, objShell, lngBiasKey
Dim lngBias, k, strDN, dtmDate, objDate, nom
Dim strBase, strFilter, strAttributes, lngHigh, lngLow

' 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
Set objShell = Nothing

' Determine DNS domain from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
Set objRootDSE = Nothing

' Use ADO to search Active Directory.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection

' Search entire domain.
strBase = ""

' Filter on all user objects.
strFilter = "(&(objectCategory=person)(objectClass=user))"

' Comma delimited list of attribute values to retrieve.
strAttributes = "distinguishedName,sAMAccountName,lastLogonTimeStamp"

' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"

' Run the query.
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 1000000
adoCommand.Properties("Timeout") = 6000
adoCommand.Properties("Cache Results") = False
Set adoRecordset = adoCommand.Execute

' Enumerate resulting recordset.
Do Until adoRecordset.EOF
' Retrieve attribute values for the user.
strDN = adoRecordset.Fields("sAMAccountName").Value
nom = adoRecordset.Fields("sAMAccountName").Value
' Convert Integer8 value to date/time in current time zone.
On Error Resume Next
Set objDate = adoRecordset.Fields("lastLogonTimeStamp").Value
If (Err.Number <> 0) Then
On Error GoTo 0
dtmDate = #1/1/1601#
Else
On Error GoTo 0
lngHigh = objDate.HighPart
lngLow = objDate.LowPart
If (lngLow < 0) Then
lngHigh = lngHigh + 1
End If
If (lngHigh = 0) And (lngLow = 0 ) Then
dtmDate = #1/1/1601#
Else
dtmDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) _
+ lngLow)/600000000 - lngBias)/1440
End If
End If
' Display values for the user.
If (dtmDate = #1/1/1601#) Then
Wscript.Echo nom & ";Never"
Else
Wscript.Echo nom & ";" & dtmDate
End If
adoRecordset.MoveNext
Loop

' Clean up.
adoRecordset.Close
adoConnection.Close
Set adoConnection = Nothing
Set adoCommand = Nothing
Set adoRecordset = Nothing
Set objDate = Nothing