Vous êtes ici : Accueil > Administration réseaux > Récupération de la liste des ordinateurs dans un domaine Active Directory

Récupération de la liste des ordinateurs dans un domaine Active Directory

J'ai eu besoin, il y a quelques temps de récupérer la liste des ordinateurs d'un domaine Active Directory. Pour éviter de les lister un par un, j'ai écrit un petit script VBS qui m'a permit de le faire en quelques secondes. Ce script permet donc de lister dans un fichiers texte tous les pcs du domaine Active Directory en excluant une OU (ici Ordinateurs supprimés) ce qui est pratique pour n'avoir que les pcs actifs du domaine. Je le met donc à disposition. Il n'est surement pas parfait donc si vous avez des remarques ou suggestions, n'hésitez pas à me le dire.

Pré-requis :

Ce script nécessite le fichier ldifde.exe (normalement présent sur les serveurs dans C:\Windows\System32)

'Listing PC AD by ced-info'

'A modifier avant utilisation :
'	- le chemin du ldif
'	- le nom du srv
'	- le chemin complet de l'OU à scanner
'	- le filtre
'	- le chemin du fichier txt qui récupère la liste des pcs

'Déclarations des variables
dim wshell, ldif, srv, OU, filtre, Computers
ldif = "computers.ldif"
Computers = "computers.txt"
srv = "SRV"
OU = "OU=Ordinateurs,DC=domain,DC=lan"
filtre = "CN=Computers,CN=Schema,CN=Configuration,DC=domain,DC=lan"

'On récupère le ldif de tout les pcs
set wshell=CreateObject("Wscript.Shell")
wshell.Run"ldifde -f " & ldif & " -s " & srv & " -d " & OU & " -p subtree -r (objectCategory=" & filtre & ")",0

'On attend 5s que le fichier soit généré en affichant un message d'attente
Set message = WScript.CreateObject("WScript.Shell")
message.Popup "Récupération de la liste des ordinateurs du domaine en cours ...",5,"..:: LISTING PC AD BY CED-INFO ::.."

'Lecture du fichier généré
'Déclarations des variables
Const Writing = 2
Dim file, f, SearchName, name, ComputersListe, OUNOK, ComputersNOK, DebutOU, FinOU, BaliseDebut, BaliseFin
OUNOK = "OU=Ordinateurs supprimés"
BaliseDebut = "CN="
BaliseFin = ",OU="
Set file = CreateObject("Scripting.FileSystemObject")
Set f = file.OpenTextFile(ldif, 1)
Set ComputersListe = file.OpenTextFile(Computers, Writing,true)

'On fait une boucle pour récuperer le nom des pcs
	Do While Not f.AtEndOfStream
		SearchName = f.ReadLine
		If left(SearchName, 2) = "dn" Then
			'On exclut les pcs de l'OU qu'on ne veut pas
			'InStr renvoi 0 si pas d'occurence trouvé sinon il renvoie sa position
			ComputersNOK = InStr(SearchName, OUNOK)
			If ComputersNOK = 0 Then
				'On récupère le nom des pcs dans le dn
				DebutOU =  InStr(1, SearchName, BaliseDebut)
				DebutOU = DebutOu + Len(BaliseDebut)
				FinOu = DebutOu
				FinOu = InStr(FinOu, SearchName, BaliseFin)
				SearchName = Mid(SearchName, DebutOu, FinOu - DebutOu)
				'On écrit le nom des pcs dans le fichiers txt
				ComputersListe.write(SearchName & vbCrlf)
			End if
		End If
	Loop
f.close

'On nettoie
file.DeleteFile(ldif)

'Fin de la création de la liste
message.Popup "La récupération de la liste des ordinateurs du domaine est terminée." & vbCrLf & "La liste des ordinateurs est consultable dans le fichier : " & Computers,20,"..:: LISTING PC AD BY CED-INFO ::.."
  • Pingback: Graduate programs at future university()

  • Pingback: خطابات توصية لجامعة المستقبل()

  • Good post! We will be linking to this particularly great post on our site. Keep up the great writing

  • I do not even understand how I ended up here, but I assumed this publish used to be great

  • I really like reading through a post that can make men and women think. Also, thank you for allowing me to comment!

  • naturally like your web site however you need to take a look at the spelling on several of your posts. A number of them are rife with spelling problems and I find it very bothersome to tell the truth on the other hand I will surely come again again.

  • You’re so awesome! I don’t believe I have read a single thing like that before. So great to find someone with some original thoughts on this topic. Really.. thank you for starting this up. This website is something that is needed on the internet, someone with a little originality!

  • Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me. https://www.binance.com/pt-PT/register?ref=PORL8W0Z

  • I am an investor of gate io, I have consulted a lot of information, I hope to upgrade my investment strategy with a new model. Your article creation ideas have given me a lot of inspiration, but I still have some doubts. I wonder if you can help me? Thanks.

  • I think the content you share is interesting, but for me there is still something missing, because the things discussed above are not important to talk about today.

  • After reading your article, it reminded me of some things about gate io that I studied before. The content is similar to yours, but your thinking is very special, which gave me a different idea. Thank you. But I still have some questions I want to ask you, I will always pay attention. Thanks.

  • Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://accounts.binance.com/pt-BR/register-person?ref=JHQQKNKN

  • Pingback: shippingtousa.mystrikingly.com()

  • I don't think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article. https://www.binance.com/pt-BR/register?ref=S5H7X3LP