script para localizar DCs

06/02/2006 - 20:28 por cristina | Informe spam
Existe alguna forma mediante un script listar tods los DCs de un AD??.
gracias.

Preguntas similare

Leer las respuestas

#1 Ramon Jiménez [MVP]
06/02/2006 - 20:50 | Informe spam
Para un dominio concreto...
http://www.rlmueller.net/Enumerate%20DCs.htm

Ramon
"cristina" wrote in message
news:%
Existe alguna forma mediante un script listar tods los DCs de un AD??.
gracias.


Respuesta Responder a este mensaje
#2 cristina
06/02/2006 - 21:14 | Informe spam
Gracias, y para que me lo vuelque a un txt, donde le pongo el parametro?

"Ramon Jiménez [MVP]" <rjimenezm_en escribió en el
mensaje news:
Para un dominio concreto...
http://www.rlmueller.net/Enumerate%20DCs.htm

Ramon
"cristina" wrote in message
news:%
Existe alguna forma mediante un script listar tods los DCs de un AD??.
gracias.


Respuesta Responder a este mensaje
#3 Ramon Jiménez [MVP]
06/02/2006 - 21:29 | Informe spam
Pues tienes que utilizar un fichero de texto...

<corta a partir de aqui>

OPTION EXPLICIT
CONST STRDCLIST = ".\\DCList.txt"

Dim oFileDC, objDCFile
Set oFileDC = CreateObject("Scripting.FileSystemObject")
Set objDCFile = oFileDC.CreateTextFile(STRDCLIST)
If Err.Number Then
Print "Error 0X" & CStr(Hex(Err.Number)) & " intentando crear el fichero
de DC's del dominio" & STRDCLIST
If Err.Description <> "" Then
Print "Error obtenido: " & Err.Description & "."
End If
objDCFile.Close
WScript.Quit
End If

'Ponemos una cabecera descriptiva al fichero
objDCFile.WriteLine("LISTADO DE CONTROLADORES DE DOMINIO")

'Ahora pongo el código del enlace que te he enviado

Dim objRootDSE, strConfig, objConnection, objCommand, strQuery
Dim objRecordSet, objDC, objSite

' Determine configuration context from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strConfig = objRootDSE.Get("configurationNamingContext")

' Use ADO to search Active Directory for ObjectClass nTDSDSA.
Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection

strQuery = "<LDAP://" & strConfig _
& ">;(ObjectClass=nTDSDSA);AdsPath;subtree"

objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False

Set objRecordSet = objCommand.Execute

' The parent object of each object with ObjectClass=nTDSDSA is a Domain
' Controller. The parent of each Domain Controller is a "Servers"
' container, and the parent of this container is the "Site" container.
Do Until objRecordSet.EOF
Set objDC = GetObject( _
GetObject(objRecordSet.Fields("AdsPath")).Parent)
Set objSite = GetObject(GetObject(objDC.Parent).Parent)
objDCFile.WriteLine( "Domain Controller: " & objDC.cn & vbCrLf & "DNS Host
Name: " & objDC.DNSHostName & vbCrLf & "Site: " & objSite.name)
objRecordSet.MoveNext
Loop

' Clean up.
objConnection.Close
Set objRootDSE = Nothing
Set objCommand = Nothing
Set objConnection = Nothing
Set objRecordSet = Nothing
Set objDC = Nothing
Set objSite = Nothing

'Ahora acabo con el codigo
set oFileDC = Nothing
set objDCFile = Nothing

objDCFile.Close

<fin del codigo>

"cristina" wrote in message
news:O4p%
Gracias, y para que me lo vuelque a un txt, donde le pongo el parametro?

"Ramon Jiménez [MVP]" <rjimenezm_en escribió en el
mensaje news:
Para un dominio concreto...
http://www.rlmueller.net/Enumerate%20DCs.htm

Ramon
"cristina" wrote in message
news:%
Existe alguna forma mediante un script listar tods los DCs de un AD??.
gracias.







Respuesta Responder a este mensaje
#4 cristina
06/02/2006 - 21:35 | Informe spam
MUCHAS GRACIAS.

"Ramon Jiménez [MVP]" <rjimenezm_en escribió en el
mensaje news:
Pues tienes que utilizar un fichero de texto...

<corta a partir de aqui>

OPTION EXPLICIT
CONST STRDCLIST = ".\\DCList.txt"

Dim oFileDC, objDCFile
Set oFileDC = CreateObject("Scripting.FileSystemObject")
Set objDCFile = oFileDC.CreateTextFile(STRDCLIST)
If Err.Number Then
Print "Error 0X" & CStr(Hex(Err.Number)) & " intentando crear el fichero
de DC's del dominio" & STRDCLIST
If Err.Description <> "" Then
Print "Error obtenido: " & Err.Description & "."
End If
objDCFile.Close
WScript.Quit
End If

'Ponemos una cabecera descriptiva al fichero
objDCFile.WriteLine("LISTADO DE CONTROLADORES DE DOMINIO")

'Ahora pongo el código del enlace que te he enviado

Dim objRootDSE, strConfig, objConnection, objCommand, strQuery
Dim objRecordSet, objDC, objSite

' Determine configuration context from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strConfig = objRootDSE.Get("configurationNamingContext")

' Use ADO to search Active Directory for ObjectClass nTDSDSA.
Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection

strQuery = "<LDAP://" & strConfig _
& ">;(ObjectClass=nTDSDSA);AdsPath;subtree"

objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False

Set objRecordSet = objCommand.Execute

' The parent object of each object with ObjectClass=nTDSDSA is a Domain
' Controller. The parent of each Domain Controller is a "Servers"
' container, and the parent of this container is the "Site" container.
Do Until objRecordSet.EOF
Set objDC = GetObject( _
GetObject(objRecordSet.Fields("AdsPath")).Parent)
Set objSite = GetObject(GetObject(objDC.Parent).Parent)
objDCFile.WriteLine( "Domain Controller: " & objDC.cn & vbCrLf & "DNS Host
Name: " & objDC.DNSHostName & vbCrLf & "Site: " & objSite.name)
objRecordSet.MoveNext
Loop

' Clean up.
objConnection.Close
Set objRootDSE = Nothing
Set objCommand = Nothing
Set objConnection = Nothing
Set objRecordSet = Nothing
Set objDC = Nothing
Set objSite = Nothing

'Ahora acabo con el codigo
set oFileDC = Nothing
set objDCFile = Nothing

objDCFile.Close

<fin del codigo>

"cristina" wrote in message
news:O4p%
Gracias, y para que me lo vuelque a un txt, donde le pongo el parametro?

"Ramon Jiménez [MVP]" <rjimenezm_en escribió en el
mensaje news:
Para un dominio concreto...
http://www.rlmueller.net/Enumerate%20DCs.htm

Ramon
"cristina" wrote in message
news:%
Existe alguna forma mediante un script listar tods los DCs de un AD??.
gracias.







Respuesta Responder a este mensaje
#5 Ramon Jiménez [MVP]
06/02/2006 - 21:36 | Informe spam
Un pequeño bug en mi codigo...

Limpia la variable despues de cerrar el fichero, nsi no da un error al
acabar

objDCFile.Close
set objDCFile = Nothing

Ramon

"Ramon Jiménez [MVP]" <rjimenezm_en wrote in message
news:
Pues tienes que utilizar un fichero de texto...

<corta a partir de aqui>

OPTION EXPLICIT
CONST STRDCLIST = ".\\DCList.txt"

Dim oFileDC, objDCFile
Set oFileDC = CreateObject("Scripting.FileSystemObject")
Set objDCFile = oFileDC.CreateTextFile(STRDCLIST)
If Err.Number Then
Print "Error 0X" & CStr(Hex(Err.Number)) & " intentando crear el
fichero de DC's del dominio" & STRDCLIST
If Err.Description <> "" Then
Print "Error obtenido: " & Err.Description & "."
End If
objDCFile.Close
WScript.Quit
End If

'Ponemos una cabecera descriptiva al fichero
objDCFile.WriteLine("LISTADO DE CONTROLADORES DE DOMINIO")

'Ahora pongo el código del enlace que te he enviado

Dim objRootDSE, strConfig, objConnection, objCommand, strQuery
Dim objRecordSet, objDC, objSite

' Determine configuration context from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strConfig = objRootDSE.Get("configurationNamingContext")

' Use ADO to search Active Directory for ObjectClass nTDSDSA.
Set objCommand = CreateObject("ADODB.Command")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection

strQuery = "<LDAP://" & strConfig _
& ">;(ObjectClass=nTDSDSA);AdsPath;subtree"

objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False

Set objRecordSet = objCommand.Execute

' The parent object of each object with ObjectClass=nTDSDSA is a Domain
' Controller. The parent of each Domain Controller is a "Servers"
' container, and the parent of this container is the "Site" container.
Do Until objRecordSet.EOF
Set objDC = GetObject( _
GetObject(objRecordSet.Fields("AdsPath")).Parent)
Set objSite = GetObject(GetObject(objDC.Parent).Parent)
objDCFile.WriteLine( "Domain Controller: " & objDC.cn & vbCrLf & "DNS
Host Name: " & objDC.DNSHostName & vbCrLf & "Site: " & objSite.name)
objRecordSet.MoveNext
Loop

' Clean up.
objConnection.Close
Set objRootDSE = Nothing
Set objCommand = Nothing
Set objConnection = Nothing
Set objRecordSet = Nothing
Set objDC = Nothing
Set objSite = Nothing

'Ahora acabo con el codigo
set oFileDC = Nothing
set objDCFile = Nothing

objDCFile.Close

<fin del codigo>

"cristina" wrote in message
news:O4p%
Gracias, y para que me lo vuelque a un txt, donde le pongo el parametro?

"Ramon Jiménez [MVP]" <rjimenezm_en escribió en el
mensaje news:
Para un dominio concreto...
http://www.rlmueller.net/Enumerate%20DCs.htm

Ramon
"cristina" wrote in message
news:%
Existe alguna forma mediante un script listar tods los DCs de un AD??.
gracias.











Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaSiguiente Respuesta Tengo una respuesta
Search Busqueda sugerida