IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBScript Discussion :

Vbs AD Lister les membres de groupe imbriqué


Sujet :

VBScript

  1. #1
    Nouveau membre du Club
    Inscrit en
    Décembre 2007
    Messages
    42
    Détails du profil
    Informations forums :
    Inscription : Décembre 2007
    Messages : 42
    Points : 35
    Points
    35
    Par défaut Vbs AD Lister les membres de groupe imbriqué
    Bonjour,

    J'ai un groupe de domaine local TOTO.
    Les membres du groupe TOTO sont deux autres groupes de domaine globaux.
    TITI et TATA.

    Dans mes 2 groupes globaux TITI et TATA j'ai les utilisateurs.

    Comment en VBS je peux avoir les utilisateurs du groupe TOTO.

    J'ai ecris le code suivant :
    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
     
    Option Explicit
    Dim ObjGroup, ObjRootDSE, ObjFichier
    Dim StrContainer,StrName
    Dim strMember,strDNSDomain,arrMemberOf,Pos,StrList,Fichier
    Const Lire = 1, Ecrire = 2, Ajouter = 8
     
    StrContainer = "OU=GROUPES,OU=SERVICE"
    strName = InputBox("Veuillez entrer le nom du groupe" & VbCrlf & "dont vous voulez les membres","Lister les utilisateurs de groupe by Vikingraver")
    If strName<>"" then
    '***********************************************
    '*         Connect to a container              *
    '***********************************************
    Set ObjRootDSE = GetObject("LDAP://rootDSE")
    Set ObjGroup = GetObject("LDAP://CN=" & StrName & "," & strContainer & "," & objRootDSE.Get("defaultNamingContext"))
    '***********************************************
    '*       End connect to a container            *
    '***********************************************
    objGroup.getInfo
    ArrMemberOf = objGroup.GetEx("member")
       For Each strMember in arrMemberOf
    	  Wscript.echo StrMember
    	  Pos=instr(strmember,",")
          strMember = Mid(strMember, 4, Pos-4)
    	  strList = strList & strMember & vbcrlf
       Next
    Set objfichier = wscript.createobject("scripting.filesystemobject")
    'si on souhaite ecraser le fichier à chaque interrogation
    'set Fichier=ObjFichier.OpenTextFile("Liste.txt",Ecrire,True)
    'Fichier.Close
     
    'si on souhaite ajouter les données
    set Fichier=ObjFichier.OpenTextFile("Liste.txt",Ajouter,true)
    Fichier.WriteLine strName & " contient :" & vbCrlf & Vbcrlf & strList
    Fichier.Close
    'Wscript.Echo strName & " contient :" & vbCrlf & Vbcrlf & strList
    End If
    Set ObjRootDSE = nothing
    Set ObjGroup = nothing
    Set ObjFichier = nothing
    Mais avec ce code je n'obtiens que la liste primaire. c'est à dire tous les noms de groupes globaux.
    Je voudrais que cela se fasse sur tous les niveaux (recursif jusqu'à je n'ai plus de groupe).

    Merci de votre aide

  2. #2
    Nouveau membre du Club
    Inscrit en
    Décembre 2007
    Messages
    42
    Détails du profil
    Informations forums :
    Inscription : Décembre 2007
    Messages : 42
    Points : 35
    Points
    35
    Par défaut
    He ben mon post ne suscite pas des vocations

  3. #3
    Nouveau membre du Club
    Inscrit en
    Décembre 2007
    Messages
    42
    Détails du profil
    Informations forums :
    Inscription : Décembre 2007
    Messages : 42
    Points : 35
    Points
    35
    Par défaut
    J'ai finalement trouvé...

    J'ai trouvé un bout de code que j'ai modifié et ca fonctionne.

    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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
     
    Option Explicit
     
    Dim StrContainer , StrGrp
    Dim objGroup, strDN, objMemberList
    Dim adoConnection, adoCommand, objRootDSE, strDNSDomain
    Dim FSO,Fichier, StrList
    Const Lire = 1, Ecrire = 2, Ajouter = 8
     
    ' Dictionary object to track group membership.
    Set objMemberList = CreateObject("Scripting.Dictionary")
    objMemberList.CompareMode = vbTextCompare
    Set FSO = Wscript.CreateObject("Scripting.FileSystemObject")
     
     
     
    StrContainer = "OU=GROUPES,OU=ORGANISATION,OU=VILLE"
    StrDN = InputBox("Veuillez entrer le nom du groupe" & VbCrlf & "dont vous voulez les membres","Lister les utilisateurs de groupe by Vikingraver entreprise")
     
     
    ' Se connecter sur le groupe
    Set objRootDSE = GetObject("LDAP://RootDSE")
    StrDNSDomain = objRootDSE.Get("defaultNamingContext")
    On Error Resume Next
    Set ObjGroup = GetObject("LDAP://CN=" & StrDN & "," & strContainer & "," & StrDNSDomain)
    If (Err.Number <> 0) Then
        On Error GoTo 0
        Wscript.Echo "Groupe non trouvé" & vbCrLf & strDN
        Wscript.Quit(1)
    End If
    On Error GoTo 0
     
    ' Setup ADO.
    Set adoConnection = CreateObject("ADODB.Connection")
    Set adoCommand = CreateObject("ADODB.Command")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    Set adoCommand.ActiveConnection = adoConnection
    adoCommand.Properties("Page Size") = 100
    adoCommand.Properties("Timeout") = 30
    adoCommand.Properties("Cache Results") = False
     
    ' Enumerer les membres du groupe
    Call EnumGroup(objGroup, "  ")
     
     
    set Fichier=FSO.OpenTextFile("Liste.txt",Ajouter,true)
    Fichier.WriteLine "********************" & VbCrlf & "Les membres de " & StrDN & " sont :" & vbCrlf & VbCrlf & "********************" & VbCrlf & Vbcrlf & VbCrlf & StrList
    Fichier.Close
     
    adoConnection.Close
    Set objGroup = Nothing
    Set objRootDSE = Nothing
    Set adoCommand = Nothing
    Set adoConnection = Nothing
     
     
    '#################################################################################
    Sub EnumGroup(ByVal objADGroup, ByVal strOffset)
        ' Recursive subroutine to enumerate group membership.
        ' objMemberList is a dictionary object with global scope.
        ' objADGroup is a group object bound with the LDAP provider.
        ' This subroutine outputs a list of group members, one member
        ' per line. Nested group members are included. Users are also
        ' included if their primary group is objADGroup. objMemberList
        ' prevents an infinite loop if nested groups are circular.
     
        Dim strFilter, strAttributes, adoRecordset, intGroupToken
        Dim objMember, strQuery, strNTName
     
        ' Retrieve "primaryGroupToken" of group.
        objADGroup.GetInfoEx Array("primaryGroupToken"), 0
        intGroupToken = objADGroup.Get("primaryGroupToken")
     
        ' Use ADO to search for users whose "primaryGroupID" matches the
        ' group "primaryGroupToken".
        strFilter = "(primaryGroupID=" & intGroupToken & ")"
        strAttributes = "sAMAccountName"
        strQuery = "<LDAP://" & strDNSDomain & ">;" & strFilter & ";" & strAttributes & ";subtree"
        adoCommand.CommandText = strQuery
        Set adoRecordset = adoCommand.Execute
        Do Until adoRecordset.EOF
            strNTName = adoRecordset.Fields("sAMAccountName").Value
            If (objMemberList.Exists(strNTName) = False) Then
                objMemberList.Add strNTName, True
                StrList = StrList & strOffset & strNTName & " (Primary)" & VbCrlf
            Else
                StrList = StrList & strOffset & strNTName & " (Primary, Duplicate)" & Vbcrlf
            End If
            adoRecordset.MoveNext
        Loop
        adoRecordset.Close
     
        For Each objMember In objADGroup.Members
            If (objMemberList.Exists(objMember.sAMAccountName) = False) Then
                objMemberList.Add objMember.sAMAccountName, True
                If (UCase(Left(objMember.objectCategory, 8)) = "CN=GROUP") Then
                    StrList = Strlist & VbCrlf & StrOffset & "-----------------------" & VbCrlf & strOffset & objMember.sAMAccountName & " (Groupe)" & VbCrlf
                    Call EnumGroup(objMember, strOffset & strOffset & strOffset)
                Else
                    StrList = StrList & strOffset & objMember.sAMAccountName & VbCrlf
                End If
            Else
                StrList = Strlist & strOffset & objMember.sAMAccountName & " (Ce compte existe deja dans un autre groupe.)" & VbCrlf
            End If
        Next
        Set objMember = Nothing
        Set adoRecordset = Nothing
    End Sub
    Voilà j'ai laissé les commentaires en anglais qui été avec le code.

    On peut glisser ce post dans vos contributions en VBscript.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 0
    Dernier message: 16/12/2013, 17h55
  2. Réponses: 12
    Dernier message: 16/03/2011, 14h07
  3. Lister les membres des groupes AD
    Par Firenight dans le forum VBScript
    Réponses: 1
    Dernier message: 10/06/2010, 11h11
  4. Lister les membres d'un groupe active directory
    Par Ludo75 dans le forum VBScript
    Réponses: 1
    Dernier message: 18/06/2008, 18h08

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo