Comment lister les Noms des postes de travail d'un domaine AD ?

Le
Teddy
Bonjour,
Voici 1 partie de mon script :

Set DomainSet = GetObject("WinNT://" & "Nom du Domaine")
DomainSet.Filter = Array("Computer")
For Each Computer In DomainSet
s = s & Computer.Name
Set IPConfigSet =
GetObject("winmgmts:{impersonationLevel=impersonate}!//" &
Computer.Name).ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE
IPEnabled=TRUE")
For Each IPConfig In IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
s = s & " | " & IPConfig.MACAddress
's = s & " | " & IPConfig.DefaultIPGateway
's = s & " | " & IPConfig.IPSubnet
For i = LBound(IPConfig.IPAddress) To
UBound(IPConfig.IPAddress)
s = s & " | " & IPConfig.IPAddress(i)
Next
s = s & vbCrLf & vbCrLf
End If
Next
Next
MsgBox s

Pour un domaine Active Directory (AD), ça ne fonctionne pas !
Il faut peut-être utiliser une requête sur l'annuaire LDAP, mais là,
GetObject("LDAP://AD") ne retourne rien mais pas d'erreur Err.Number,
bizarre non ?
Si quelqu'un avait - par hasard - une (bonne) idée
Merci d'avance ;-)
Ted
  • Partager ce contenu :
Vos réponses
Trier par : date / pertinence
news1
Le #521370
Voici un script qui liste le PC ainsi que la dernière connexion



Public Const ADS_SCOPE_BASE = 0
Public Const ADS_SCOPE_ONELEVEL = 1
Public Const ADS_SCOPE_SUBTREE = 2

filelog="pc_lastlogon.txt"
set oFSO = CreateObject("Scripting.FileSystemObject")
set file_res = oFSO.OpenTextFile (filelog,2, True)
'-------------------------------------------------------------------------- ------
' ADO Query
'-------------------------------------------------------------------------- ----


Set con = CreateObject("ADODB.Connection")
Set com = CreateObject("ADODB.Command")

'Open a Connection object
con.Provider = "ADsDSOObject"



'------------------------------------
' Open the connection
'-------------------------------------
con.Open "Active Directory Provider"

' Create a command object on this connection
Set Com.ActiveConnection = con

'--------------------------------------------------
' set the query string


adDomainPath = "LDAP://dc/DC=toto,DC=com"

Com.CommandText = "select name,lastlogon from '" & adDomainPath &
"' where objectClass='computer' ORDER BY NAME"


'-----------------------------------------
'Set the preferences for Search
'--------------------------------------
Com.Properties("Page Size") = 1000
Com.Properties("Timeout") = 30 'seconds
Com.Properties("searchscope") = ADS_SCOPE_SUBTREE 'Define in
ADS_SCOPEENUM
Com.Properties("Cache Results") = False ' do not cache the result,
it results in less memory requirements


'--------------------------------------------
'Execute the query
'--------------------------------------------
Set rs = Com.Execute


'--------------------------------------
' Navigate the record set
'----------------------------------------
rs.MoveFirst

number = 0
While Not rs.EOF
' wscript.echo rs.Fields("Name").Value
sDate = rs.Fields("LastLogon")
Set oDate = sDate
nDate = #1/1/1601# + (((oDate.HighPart * (2 ^ 32)) +
oDate.LowPart)/600000000 - nBias)/1440
file_res.writeline rs.Fields("Name").Value&","&nDate
' wscript.echo nDate

rs.MoveNext
number = number + 1
Wend

'wscript.echo ""
'wscript.echo number, "computer"
msgbox "Analyse terminée"
file_res.close
Teddy
Le #521367
Merci beaucoup. Je vais voir ce script.
Ce qui m'ennuie, c'est que j'ai des domaines NT4 et AD dans le réseau.
Je vais donc devoir faire plusieurs scripts selon le domaine : c'est pas très pratique.
Ted


Voici un script qui liste le PC ainsi que la dernière connexion



Public Const ADS_SCOPE_BASE = 0
Public Const ADS_SCOPE_ONELEVEL = 1
Public Const ADS_SCOPE_SUBTREE = 2

filelog="pc_lastlogon.txt"
set oFSO = CreateObject("Scripting.FileSystemObject")
set file_res = oFSO.OpenTextFile (filelog,2, True)
'--------------------------------------------------------------------------------
' ADO Query
'------------------------------------------------------------------------------


Set con = CreateObject("ADODB.Connection")
Set com = CreateObject("ADODB.Command")

'Open a Connection object
con.Provider = "ADsDSOObject"



'------------------------------------
' Open the connection
'-------------------------------------
con.Open "Active Directory Provider"

' Create a command object on this connection
Set Com.ActiveConnection = con

'--------------------------------------------------
' set the query string


adDomainPath = "LDAP://dc/DC=toto,DC=com"

Com.CommandText = "select name,lastlogon from '" & adDomainPath &
"' where objectClass='computer' ORDER BY NAME"


'-----------------------------------------
'Set the preferences for Search
'--------------------------------------
Com.Properties("Page Size") = 1000
Com.Properties("Timeout") = 30 'seconds
Com.Properties("searchscope") = ADS_SCOPE_SUBTREE 'Define in
ADS_SCOPEENUM
Com.Properties("Cache Results") = False ' do not cache the result,
it results in less memory requirements


'--------------------------------------------
'Execute the query
'--------------------------------------------
Set rs = Com.Execute


'--------------------------------------
' Navigate the record set
'----------------------------------------
rs.MoveFirst

number = 0
While Not rs.EOF
' wscript.echo rs.Fields("Name").Value
sDate = rs.Fields("LastLogon")
Set oDate = sDate
nDate = #1/1/1601# + (((oDate.HighPart * (2 ^ 32)) +
oDate.LowPart)/600000000 - nBias)/1440
file_res.writeline rs.Fields("Name").Value&","&nDate
' wscript.echo nDate

rs.MoveNext
number = number + 1
Wend

'wscript.echo ""
'wscript.echo number, "computer"
msgbox "Analyse terminée"
file_res.close
Poster une réponse
Anonyme