|
Sujet : Script vbs pour mapper des lecteurs réseaux AD |
| podeniak |
Bonjour,
Nickel ton script, je faisait du mappage avec kixtart sur mon domaine, sauf qu'avec les postes en win7, on a quelques difficultés... Et là ton script m'arrange carrément.
Par contre j'ai fais une petite modif, j'ai rajouté des lignes pour virer le lecteur existant, ca peut etre utile lors du changement du serveur de fichier.
Code :
- Dim objRootLDAP, objGroup, objUser, objOU, objmemberOf, FSO
- Dim strOU, strUser, strDNSDomain, strLDAP, List, objADSysInfo, arr, intlength, intNamelength, strGroupName
- ' Commands to bind to AD
- Set objRootLDAP = GetObject("LDAP://RootDSE" )
- Set objNetwork = CreateObject("Wscript.Network" )
- Set fso = CreateObject("Scripting.FileSystemObject" )
- ' Supression du lecteur V: Si il existe
- If FSO.DriveExists ("V:" ) Then
- objNetwork.RemoveNetworkDrive "V:", true, true
- End If
- 'trouver le DN de l'utilisateur
- Set objADSysInfo = CreateObject("ADSystemInfo" )
- strUser = objADSysInfo.UserName
- Set objUser = GetObject("LDAP://" & strUser)
- ' Extract a list of Groups from memberOf
- objmemberOf = objUser.GetEx("memberOf" )
- For Each objGroup in objmemberOf
- List = List & objGroup & vbCr
- arr=Split(List,"," )
- intlength=Len(arr(0))
- intNamelength=intlength - 3
- Next
- strGroupName= Right(arr(0), intNameLength)
- 'Connecter un lecteur en fonction du groupe
- Select Case strGroupName
- Case "GG-3A"
- objNetwork.MapNetworkDrive "V:", "\\SRV-2K3\PARTAGES$\COMMUNS\3EME\3A"
-
- Case "GG-3B"
- objNetwork.MapNetworkDrive "V:", "\\SRV-2K3\PARTAGES$\COMMUNS\3EME\3B"
- Case "GG-4A"
- objNetwork.MapNetworkDrive "V:", "\\SRV-2K3\PARTAGES$\COMMUNS\4EME\4A"
- Case "GG-4B"
- objNetwork.MapNetworkDrive "V:", "\\SRV-2K3\PARTAGES$\COMMUNS\4EME\4B"
- Case "GG-5A"
- objNetwork.MapNetworkDrive "V:", "\\SRV-2K3\PARTAGES$\COMMUNS\5EME\5A"
- Case "GG-5B"
- objNetwork.MapNetworkDrive "V:", "\\SRV-2K3\PARTAGES$\COMMUNS\5EME\5B"
- Case "GG-6A"
- objNetwork.MapNetworkDrive "V:", "\\SRV-2K3\PARTAGES$\COMMUNS\6EME\6A"
- Case "GG-6B"
- objNetwork.MapNetworkDrive "V:", "\\SRV-2K3\PARTAGES$\COMMUNS\6EME\6B"
- End Select
-
- WScript.Quit
|
J'ai mis en rouge les lignes que j'ai greffé.
En esperant que ca vous soit utile.
Podeniak |
| podeniak |
Bonjour,
Nickel ton script, je faisait du mappage avec kixtart sur mon domaine, sauf qu'avec les postes en win7, on a quelques difficultés... Et là ton script m'arrange carrément.
Par contre j'ai fais une petite modif, j'ai rajouté des lignes pour virer le lecteur existant, ca peut etre utile lors du changement du serveur de fichier.
Code :
- Dim objRootLDAP, objGroup, objUser, objOU, objmemberOf, FSO
- Dim strOU, strUser, strDNSDomain, strLDAP, List, objADSysInfo, arr, intlength, intNamelength, strGroupName
- ' Commands to bind to AD
- Set objRootLDAP = GetObject("LDAP://RootDSE" )
- Set objNetwork = CreateObject("Wscript.Network" )
- Set fso = CreateObject("Scripting.FileSystemObject" )
- ' Supression du lecteur V: Si il existe
- If FSO.DriveExists ("V:" ) Then
- objNetwork.RemoveNetworkDrive "V:", true, true
- End If
- 'trouver le DN de l'utilisateur
- Set objADSysInfo = CreateObject("ADSystemInfo" )
- strUser = objADSysInfo.UserName
- Set objUser = GetObject("LDAP://" & strUser)
- ' Extract a list of Groups from memberOf
- objmemberOf = objUser.GetEx("memberOf" )
- For Each objGroup in objmemberOf
- List = List & objGroup & vbCr
- arr=Split(List,"," )
- intlength=Len(arr(0))
- intNamelength=intlength - 3
- Next
- strGroupName= Right(arr(0), intNameLength)
- 'Connecter un lecteur en fonction du groupe
- Select Case strGroupName
- Case "GG-3A"
- objNetwork.MapNetworkDrive "V:", "\\SRV-2K3\PARTAGES$\COMMUNS\3EME\3A"
-
- Case "GG-3B"
- objNetwork.MapNetworkDrive "V:", "\\SRV-2K3\PARTAGES$\COMMUNS\3EME\3B"
- Case "GG-4A"
- objNetwork.MapNetworkDrive "V:", "\\SRV-2K3\PARTAGES$\COMMUNS\4EME\4A"
- Case "GG-4B"
- objNetwork.MapNetworkDrive "V:", "\\SRV-2K3\PARTAGES$\COMMUNS\4EME\4B"
- Case "GG-5A"
- objNetwork.MapNetworkDrive "V:", "\\SRV-2K3\PARTAGES$\COMMUNS\5EME\5A"
- Case "GG-5B"
- objNetwork.MapNetworkDrive "V:", "\\SRV-2K3\PARTAGES$\COMMUNS\5EME\5B"
- Case "GG-6A"
- objNetwork.MapNetworkDrive "V:", "\\SRV-2K3\PARTAGES$\COMMUNS\6EME\6A"
- Case "GG-6B"
- objNetwork.MapNetworkDrive "V:", "\\SRV-2K3\PARTAGES$\COMMUNS\6EME\6B"
- End Select
-
- WScript.Quit
|
J'ai mis en rouge les lignes que j'ai greffé.
En esperant que ca vous soit utile.
Podeniak |
| cmoa2 |
Tout à fait c'est bien le problème que j'avais... Mais j'ai enfin réussi ! Après de nombreuses recherches et de nombreux essais je suis parvenue à ce que je voulais :) Je donne mon script pour ceux qui pourraient en avoir besoin :
Dim objRootLDAP, objGroup, objUser, objOU, objmemberOf
Dim strOU, strUser, strDNSDomain, strLDAP, List, objADSysInfo,arr,intlength,intNamelength,strGroupName
' Commands to bind to AD
Set objRootLDAP = GetObject("LDAP://RootDSE" )
Set objNetwork = CreateObject("Wscript.Network" )
'trouver le DN de l'utilisateur
Set objADSysInfo = CreateObject("ADSystemInfo" )
strUser = objADSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
' Extract a list of Groups from memberOf
objmemberOf = objUser.GetEx("memberOf" )
For Each objGroup in objmemberOf List = List & objGroup & vbCr
arr=Split(List,"," )
intlength=Len(arr(0))
intNamelength=intlength - 3
Next
strGroupName= Right(arr(0), intNameLength)
'Connecter un lecteur en fonction du groupe
Select Case strGroupName
Case "Etudiant"
objNetwork.MapNetworkDrive "X:", "\\Serveur\Partage"
Case "Personnel" objNetwork.MapNetworkDrive "X:", "\\Serveur\Partage"
End Select
WScript.Quit
Il fonctionne et mappe les lecteurs en fonction du groupe de l'utilisateur ;)
Cependant, si vous pensez qu'une solution est meilleure que l'utilisation d'un script comme celui, faites m'en part ! :) Merci ! |
| cmoa2 |
Bonjour :) Je débute en vbs et je cherche à créer un script d'ouverture de session qui me permette de mapper un lecteur réseau à un utilisateur en fonction du groupe auquel il appartient dans Active Directory. En m'inspirant de tout ce que j'ai vu, j'obtiens un début de code qui ressemble à ceci :
Dim objRootLDAP, objGroup, objUser, objOU, objmemberOf
Dim strOU, strUser, strDNSDomain, strLDAP, strList, objADSysInfo,arr,intlength,intNamelength,objRecordSet
' Commands to bind to AD and extract domain name
Set objRootLDAP = GetObject("LDAP://RootDSE" )
strDNSDomain = objRootLDAP.Get("DefaultNamingContext" )
'find the user DN
Set objADSysInfo = CreateObject("ADSystemInfo" )
strUser = objADSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
' Extract a list of Groups from memberOf
objmemberOf = objUser.GetEx("memberOf" )
For Each objGroup in objmemberOf strList = strList & objGroup & vbCr
Next
WScript.Echo strList
J'arrive donc à récupérer le username de l'utilisateur puis à trouver les groupes auxquels il appartient. Mais voila, l'affichage de mes groupes se présente ainsi : CN=NomGroupe,CN=users,DC=test,DC=fr . Je voudrais à partir de ceci récuper seulement le nom du groupe pour pouvoir ensuite mapper les lecteurs en faisant un "case NomGroupe=Etudiant..." Si vous pouviez me donner une petite piste car là je suis un peu bloquée :pt1cable: Ou peut être auriez vous une meilleure idée pour connecter des lecteurs réseaux aux utilisateurs...une solution plus simple ou plus efficace qu'un script vbs à laquelle je n'aurai pas pensé... :) Merci ! |