Option Explicit 'Script placé sur le répertoire local du DC dans : 'C:\Windows\SYSVOL\sysvol\NomDomaine\SCRIPTS Dim WSHShell, MyCommand Dim ReturnGroupName Set WSHShell = CreateObject("WScript.Shell") On Error Resume Next MyCommand = "Net Use I: /Delete" WSHShell.Run MyCommand MyCommand = "Net Use J: /Delete" WSHShell.Run MyCommand WScript.Sleep 500 'Attente de 0,5 secondes MyCommand = "cmd /c start Net Use I: ""\\NomServeurFichiers\NomPartage01""" WSHShell.Run MyCommand ReturnGroupName = FindGroupName() If Len(ReturnGroupName) > 0 Then MyCommand = "cmd /c Start Net Use J: ""\\NomServeurFichiers\Stations\" & ReturnGroupName & """" 'Wscript.echo MyCommand WSHShell.Run MyCommand End If Set WSHShell = Nothing Function FindGroupName() Dim MyDistinguishedName Dim WSHNetwork Dim DomainString, UserString Dim objRootDSE, objItem, objConnection, objCommand, objRecordSet, objRecordSetforGroups, MyCommandText Dim strContainer, strname Dim sAMAccountName, objUser, objmemberOf, objGroup, objOneGroup Dim strOU, LineWithGroups, GroupsArray, OneGroupName, GroupeTrouve Const ADS_UF_ACCOUNTDISABLE = 2 Const ADS_SCOPE_SUBTREE = 2 'Return a groupname default value FindGroupName = "" strOU = "OU=VDI_VIEW" 'Nom de l'OU qui contient les groupes avec lesquels on va faire une comparaison 'strContainer = "" 'Si vous souhaitez vous connecter à une OU en particulié, indiquez la ici Set WSHNetwork = CreateObject("WScript.Network") DomainString = Wshnetwork.UserDomain UserString = WSHNetwork.UserName sAMAccountName = UserString 'Wscript.echo "Login : " & UserString If Len(sAMAccountName) > 0 Then On Error Resume Next Set objRootDSE = GetObject("LDAP://rootDSE") If strContainer = "" Then Set objItem = GetObject("LDAP://" & objRootDSE.Get("defaultNamingContext")) Else Set objItem = GetObject("LDAP://" & strContainer & "," & objRootDSE.Get("defaultNamingContext")) End If On Error Goto 0 'strname = objItem.Get("name") 'WScript.Echo "name: " & strname MyDistinguishedName = objItem.Get("distinguishedName") 'Récupération du distinguishedName du domaine par défaut. Exemple DC=Cotonso,DC=Com 'WScript.Echo "distinguishedName: " & MyDistinguishedName Set objConnection = CreateObject("ADODB.Connection") objConnection.Open "Provider=ADsDSOObject;" 'Récupération des groupes de l OU Set objCommand = CreateObject("ADODB.Command") objCommand.ActiveConnection = objConnection objCommand.CommandText = ";(objectCategory=Group);name,cn,displayName,sAMAccountName,distinguishedName,member;subtree" objCommand.Properties("Page Size") = 10000 objCommand.Properties("Timeout") = 30 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE objCommand.Properties("Cache Results") = False Set objRecordSet = objCommand.Execute 'WScript.echo "Liste des groupes" LineWithGroups = "" Do Until objRecordset.EOF LineWithGroups = LineWithGroups & objRecordset.Fields("sAMAccountName") & ";" 'WScript.echo VbTab & objRecordset.Fields("sAMAccountName") objRecordset.MoveNext Loop objRecordSet.Close Set objRecordSet = Nothing If Len(LineWithGroups) > 1 Then LineWithGroups = Left(LineWithGroups,Len(LineWithGroups)-1) 'On retire le dernier caractère, soit ; 'Si on a récupéré des groupes If Len(LineWithGroups) > 0 Then GroupsArray = Split(LineWithGroups,";") 'Listage des groupes du users Set objCommand = CreateObject("ADODB.Command") objCommand.ActiveConnection = objConnection objCommand.CommandText = ";(&(objectCategory=User)(sAMAccountName=" & sAMAccountName & "));name,cn,displayName,sn,mail,mailNickname,sAMAccountName,distinguishedName,memberof;subtree" Set objRecordSet = objCommand.Execute Do Until objRecordset.EOF 'WScript.echo objRecordset.Fields("distinguishedName") 'WScript.echo "Name : " & VbTab & objRecordset.Fields("Name") 'WScript.echo VbTab & "cn : " & VbTab & objRecordset.Fields("cn") 'WScript.echo VbTab & "displayName : " & VbTab & objRecordset.Fields("displayName") 'WScript.echo VbTab & "sn : " & VbTab & objRecordset.Fields("sn") 'WScript.echo VbTab & "mail : " & VbTab & objRecordset.Fields("mail") 'WScript.echo VbTab & "mailNickname : " & VbTab & objRecordset.Fields("mailNickname") 'WScript.echo VbTab & "sAMAccountName : " & VbTab & objRecordset.Fields("sAMAccountName") 'WScript.echo VbTab & "distinguishedName : " & VbTab & objRecordset.Fields("distinguishedName") 'WScript.echo "" objmemberOf = objRecordset.Fields("memberof") MyCommandText = "" GroupeTrouve = 0 For Each objGroup in objmemberOf If GroupeTrouve = 0 Then 'Wscript.echo "Connexion à : " & objGroup Set objOneGroup = GetObject("LDAP://" & objGroup) 'WScript.echo VbTab & objOneGroup.sAMAccountName 'On liste les groupes qui existent dans l'OU visée For Each OneGroupName In GroupsArray 'WScript.echo VbTab & OneGroupName If OneGroupName = objOneGroup.sAMAccountName Then 'WScript.echo "Trouvé ! : " & OneGroupName GroupeTrouve = 1 FindGroupName = OneGroupName Exit For End If Next End If Set objOneGroup = Nothing Next objRecordset.MoveNext Loop objRecordSet.Close End If objConnection.Close Else 'Wscript.echo "Login vierge : Arrêt" End If Set WSHNetwork = Nothing End Function