Bonjour à tous,
Je précise que je ne suis débutant en vbs donc tout aide est la bienvenue

Mon besoin est le suivant:

1:Supprimer tous les imprimantes réseaux à l’exception des imprimantes par défaut --> OK

2:Récupérer la liste des groupes Active Directory dont l'utilisateur fait partie

3:Récupérer la liste des groupe de l'OU Active Directory IMPR64-HP

4:Tester si le groupe 1 récupérer en partie 2 et tester si il existe dans l'OU IMPR64-HP, si oui on mappe l'imprimante sous la forme \\IMPR64-HP\Nom_du_groupe1 si non --> étapes 5

5:Tester si le groupe 1 récupérer en partie 2 et tester si il existe dans l'OU IMPR64-DIV, si oui on mappe l'imprimante sous la forme \\IMPR64-HP\Nom_du_groupe1 si non --> étapes 6

6:Tester si le groupe 1 récupérer en partie 2 et tester si il existe dans l'OU IMPR64-RICOH, si oui on mappe l'imprimante sous la forme \\IMPR64-HP\Nom_du_groupe1 si non --> étapes 7

7:On recommence à l'étape 4 avec le groupe 2 de l'utilisateur.

Après 2 jours de recherche je peine vraiment et vraiment besoin d'aide externe.
Voici mon ébauche, mes condition if on l'air de se remplir même quand le groupe n'est pas vérifié et aussi j'aurais besoin de la variable groupe2 ( Ex: CN=GROUPE) sans les 3 premiers caractères pour en faire une variable groupe (Ex: GROUPE)

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
 
on error resume next
Dim objRootLDAP, objGroup, objUser, objOU, objmemberOf
Dim strOU, strUser, strDNSDomain, strLDAP, List, objADSysInfo,arr,intlength,intNamelength,strGroupName,groupe2
Set WSHNetwork = WScript.CreateObject("WScript.Network")
Set UserName = GetObject("WinNT://" & WSHNetwork.UserDomain & "/" & WshNetwork.username)
Set objRootLDAP = GetObject("LDAP://RootDSE" )
Set objNetwork = CreateObject("Wscript.Network" )
Set objADSysInfo = CreateObject("ADSystemInfo" )
strUser = objADSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
'=============================================================================================================
'Suppression de toutes les imprimantes à l'exeption de celle par defaut
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Default = FALSE AND Network = TRUE")
 
For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next
'=============================================================================================================
'Récupération de la liste des groupes Active Directory
'EN TEST#######################################################################################################
objmemberOf = objUser.GetEx("memberOf" )
For Each objGroup in objmemberOf
List = List & objGroup & vbCr
arr=Split(List,"," )
intlength=Len(arr(0))
intNamelength=intlength - 3
groupes2 = Split(objGroup,",",2)
groupeHp = Groupe2
groupeDiv = Groupe2
groupeRicoh = Groupe2
'#######################################################################################################
'groupe = groupe2_sans_les_3_premier caractéres
'groupes2 affiche CN=GROUPE --> A modifier afin de n'avoir que GROUPE
'groupe
'#######################################################################################################
'=============================================================================================================
'Liste des groupes de l'OU IMPR64-HP
Set objOUHp = GetObject("LDAP://OU=IMPR64-HP,OU=DOMAINE,DC=DOM,DC=LOCAL")
objOUHp.Filter = Array("Group")
For Each objGroupHp in objOUHp
If objGroupHp.Name = groupeHp(0) Then
wscript.echo "OK HP"
WshNetwork.AddWindowsPrinterConnection "\\IMPR64-HP\MATT_IMP_16" 'Forcé en dur le temps que la variable groupe soir OK
'WshNetwork.AddWindowsPrinterConnection "\\IMPR64-HP\" & groupe ' Sera utilisé quand la varible groupe sera OK
End If
Next
'=============================================================================================================
'Liste des groupes de l'OU IMPR64-DIV
Set objOUDiv = GetObject("LDAP://OU=IMPR64-DIV,OU=DOMAINE,DC=DOM,DC=LOCAL")
objOUDiv.Filter = Array("Group")
For Each objGroupDiv in objOUDiv
If objGroupDiv.Name = groupeDiv(0) Then
wscript.echo "OK DIV"
WshNetwork.AddWindowsPrinterConnection "\\IMPR64-HP\MATT_IMP_23" 'Forcé en dur le temps que la variable groupe soir OK
'WshNetwork.AddWindowsPrinterConnection "\\IMPR64-DIV\" & groupe ' Sera utilisé quand la varible groupe sera OK
End If
Next
'=============================================================================================================
'Liste des groupes de l'OU IMPR64-RICOH
Set objOURicoh = GetObject("LDAP://OU=IMPR64-RICOH,OU=DOMAINE,DC=DOM,DC=LOCAL")
objOURicoh.Filter = Array("Group")
For Each objGroupRicoh in objOURicoh
If objGroupRicoh.Name = groupeRicoh(0) Then
wscript.echo "OK RICOH"
WshNetwork.AddWindowsPrinterConnection "\\IMPR64-HP\MATT_IMP_30" 'Forcé en dur le temps que la variable groupe soir OK
'WshNetwork.AddWindowsPrinterConnection "\\IMPR64-RICOH\" & groupe ' Sera utilisé quand la varible groupe sera OK
End If
Next
'=============================================================================================================
Next