Localiser un PC dans AD

Pourquoi ?

Pour savoir ou est situé un PC qui se connecte.


Principe :

Si les PCs ont été rangés par Salle et secteur dans AD, une requête AD pour obtenir de nomDN de l'ordinateur.


sDomaine=Mondomaine

Set objConnection = CreateObject("ADODB.Connection") ' connexion à AD
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection=objConnection

PDepart = "<LDAP://DC=" &sDomaine &",DC=local>"
Cond= "(&(name="& sOrdi &")(objectcategory=Computer))"
Recup = "memberof,distinguishedname"
objCommand.CommandText= PDepart&";"&Cond&";"&Recup&";subtree"
Set Oresult=objCommand.Execute

IF Oresult.RecordCount = 1 Then
champs=split(oResult.Fields("distinguishedname"),",")
OU = split(champs(1),"=")
salle = OU(1)
OU = Split(champs(2),"=")
secteur = OU(1)
WScript.echo "Salle de l'ordinateur : " & salle
WScript.Echo "Secteur : "&secteur
Else
salle=""
End IF