1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
'##############################################
'##== DSI Stendhal - Pôle Technique - 2010 ==##
'##== Tristan Fleury ==##
'##== tristan.fleury@u-grenoble3.fr ==##
'##== Script AD - Recuperation Groupe ==##
'##############################################
'##==============================================##
'## Déclaration des variables et objets global ==##
'##==============================================##
Option Explicit
on error resume next
Dim Shell, FSO, WshNetwork
Set Shell = Wscript.CreateObject ("Wscript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = CreateObject ("WScript.Network")
Dim objRootLDAP, objGroup, objUser, objOU, objmemberOf
Dim strOU, strComputer, strDNSDomain, strLDAP, strList
Dim Definition_Groupe, obj_Definition_Groupe, Groupe, Imprimante_Groupe, PrinterPath
Dim Computer, Fichier_Log, Serveur_Imp, test
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Serveur_Imp = "SERVPRINT"
Computer = Shell.ExpandEnvironmentStrings ("%COMPUTERNAME%")
Set Fichier_Log = FSO.OpenTextFile("c:\test.txt", ForAppending,true)
'##==================================##
'##== Connexion à Active Directory ==##
'##==================================##
Set objRootLDAP = GetObject("LDAP://RootDSE")
strDNSDomain = objRootLDAP.Get("DefaultNamingContext")
'##====================================================##
'##== Construction et récupération du DN sur le LDAP ==##
'##====================================================##
strComputer = "cn=" & Computer & ","
strOU ="CN=Computers,"
strLDAP ="LDAP://" & strComputer & strOU & strDNSDomain
Set objUser = GetObject(strLDAP)
'##============================================================##
'##== Récupération des groupes auquels appartient la machine ==##
'##============================================================##
objmemberOf = objUser.GetEx("memberOf")
For Each objGroup in objmemberOf
Definition_Groupe = Split(objGroup, ",")
For Each obj_Definition_Groupe in Definition_Groupe
Groupe = Split(obj_Definition_Groupe,"=")
if Groupe(0)="CN" Then
Imprimante_Groupe = Split(Groupe(1), "_")
if Imprimante_Groupe(0)="Imp" Then
PrinterPath = "\\" & Serveur_Imp & "\" & Imprimante_Groupe(1)
WshNetwork.RemovePrinterConnection PrinterPath, true, true
test = WshNetwork.AddwindowsPrinterConnection (PrinterPath)
MsgBox(test)
Fichier_Log.writeline(date & " Connection Imprimante " & Imprimante_Groupe(1) & " réussie")
end if
end if
Next
Next
WScript.Quit |
Partager