Meilleur auteur de réponses
lister les Comptes ordinateurs Actif via script

Question
-
Bonjour
Novice en programmation pouvez-vous m'aider? ^^
Je souhaites créer un script qui ecrive dans un fichier la liste des ordinateurs Actifs contenue dans une OU spécifique.
J'ai trouvé un exemple mais j'ai du mal à le personnalisé...
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select Name, Location from 'LDAP://DC=fabrikam,DC=com' " _
& "Where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
Wscript.Echo "Location: " & objRecordSet.Fields("Location").Value
objRecordSet.MoveNext
Loop
pouvez-vous me donner une piste *??
Merci d'avance- Déplacé swapnilpBanned jeudi 4 février 2010 00:46 Forum Consolidation (Origine :Windows Server 2003 – Services d’Annuaire)
jeudi 22 mai 2008 12:53
Réponses
-
Bonjour,
souhaites-tu nécessairement utiliser ton script pour cela ? Car tu as deja des outils Microsoft pour faire cela (dsquery computer -inactive (si j'ai bien compris ce que tu voulais dire par "actif"))
@bientôt
jeudi 22 mai 2008 17:30 -
Re,
Merci de ta reponse rapide
Effectivement c'est une solution, il me suffirait de soustraire le nombre trouvé grace à ta requete au nombre de computer.
entre temps j'ai trouvé, j'utilise l'objet 'userAccountControl'
Etant donné que c'est pour des indicateurs, je mets tout dans un fichier xls.
=======================================
On Error Resume Next
Const TARGET_OU = "OU=Postes,OU=MonOU,DC=MonDC,DC=toto,DC=fr"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.AddobjExcel.Cells(1, 1).Value = "Common Name"
objExcel.Cells(1, 2).Value = "whenChanged"
objExcel.Cells(1, 3).Value = "Statut"Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
"<LDAP://" & TARGET_OU & ">;(objectCategory=computer)" & _
";userAccountControl,cn,whenChanged;subtree"
Set objRecordSet = objCommand.Execute
i = 2
Do Until objRecordset.EOF
objExcel.Cells(i, 1).Value = objRecordset.Fields("cn")
objExcel.Cells(i, 2).Value = objRecordset.Fields("whenChanged")
objExcel.Cells(i, 3).Value = objRecordset.Fields("userAccountControl")
i = i+1
objRecordset.MoveNext
Loop
wscript.echo "FIN DU SCRIPT"================================
Merci à tous
vendredi 23 mai 2008 09:23
Toutes les réponses
-
Bonjour,
souhaites-tu nécessairement utiliser ton script pour cela ? Car tu as deja des outils Microsoft pour faire cela (dsquery computer -inactive (si j'ai bien compris ce que tu voulais dire par "actif"))
@bientôt
jeudi 22 mai 2008 17:30 -
Re,
Merci de ta reponse rapide
Effectivement c'est une solution, il me suffirait de soustraire le nombre trouvé grace à ta requete au nombre de computer.
entre temps j'ai trouvé, j'utilise l'objet 'userAccountControl'
Etant donné que c'est pour des indicateurs, je mets tout dans un fichier xls.
=======================================
On Error Resume Next
Const TARGET_OU = "OU=Postes,OU=MonOU,DC=MonDC,DC=toto,DC=fr"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.AddobjExcel.Cells(1, 1).Value = "Common Name"
objExcel.Cells(1, 2).Value = "whenChanged"
objExcel.Cells(1, 3).Value = "Statut"Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
"<LDAP://" & TARGET_OU & ">;(objectCategory=computer)" & _
";userAccountControl,cn,whenChanged;subtree"
Set objRecordSet = objCommand.Execute
i = 2
Do Until objRecordset.EOF
objExcel.Cells(i, 1).Value = objRecordset.Fields("cn")
objExcel.Cells(i, 2).Value = objRecordset.Fields("whenChanged")
objExcel.Cells(i, 3).Value = objRecordset.Fields("userAccountControl")
i = i+1
objRecordset.MoveNext
Loop
wscript.echo "FIN DU SCRIPT"================================
Merci à tous
vendredi 23 mai 2008 09:23 -
vendredi 23 mai 2008 10:15
-
Bonjour,
le dsquery ne fonctionne que sous 2k3 serveur ?
Cordialementmardi 18 août 2009 15:45