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 :

Obtenir utilisateur d'un groupe AD et des sous-groupe


Sujet :

VBScript

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2010
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2010
    Messages : 7
    Points : 3
    Points
    3
    Par défaut Obtenir utilisateur d'un groupe AD et des sous-groupe
    Bonjour,

    J'aimerai faire un script en VBS pour récupérer tous les utilisateurs d'un groupe Active Directory ainsi que les utilisateurs qui sont dans les sous groupes.

    Par exemple un groupe qui se nomme "Informatique" dans le quel il y a le groupe "Developpement", "Projet" et "Administration".
    Les groupes "Developpement", "Projet" et "Administration" sont composé d'utilisateurs. J'aimerai obtenir tous les utilisateurs en indiquant juste le groupe "Informatique".

    Merci d'avance pour votre aide.

  2. #2
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 836
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 836
    Points : 9 217
    Points
    9 217
    Par défaut
    Citation Envoyé par nicostunt57 Voir le message
    Bonjour,
    J'aimerai faire un script en VBS pour récupérer tous les utilisateurs d'un groupe Active Directory ainsi que les utilisateurs qui sont dans les sous groupes.
    Par exemple un groupe qui se nomme "Informatique" dans le quel il y a le groupe "Developpement", "Projet" et "Administration".
    Les groupes "Developpement", "Projet" et "Administration" sont composé d'utilisateurs. J'aimerai obtenir tous les utilisateurs en indiquant juste le groupe "Informatique".
    Merci d'avance pour votre aide.
    Salut, Voila j'ai trouvé ce script pour vous. J'espère qu'il va t'aider un peu
    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
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    ' ----------------------------------------------------------
    ' Script VBS d'affichage sous EXCEL de la liste des
    ' des groupes et comptes sur une machine locale ou distante
    ' Syntaxe:
    '	accountlist [<ordinateur>]
    '		<ordinateur> : nom de machine
    '	                   si absent : ordinateur local
    ' JC BELLAMY © 2004
    ' ----------------------------------------------------------
     
    Dim net, computer, args, GUSet, Group, User, GDict,UDict, Members, Groups
     
    ' Constantes EXCEL
    ' ----------------
    Const xlDiagonalDown       = 5
    Const xlDiagonalUp         = 6
    Const xlEdgeLeft           = 7
    Const xlEdgeTop            = 8
    Const xlEdgeBottom         = 9
    Const xlEdgeRight          =10
    Const xlContinous          = 1
    Const xlThin               = 2
    Const xlMedium	           =&HFFFFEFD6
    Const xlThick              = 4
    Const xlDouble             =&HFFFFEFE9
    Const xlAutomatic          =&HFFFFEFF7
    Const xlInsideVertical     = 11
    Const xlInsideHorizontal   = 12
    Const xlNone               =&HFFFFEFD2
    Const xlUnderlineStyleNone =&HFFFFEFD2
    Const xlCenter             =&HFFFFEFF4
    Const xlBottom             =&HFFFFEFF5
    Const xlContext            =&HFFFFEC76
    Const xlSolid              = 1
    Const msoFalse             = 0
    Const msoScaleFromTopLeft  = 0
     
    Const xlR1C1               =&HFFFFEFCA
     
    ' Couleurs EXCEL
    ' --------------
    Black         =  1
    Brown         = 53
    OliveGreen    = 52
    DarkGreen     = 51
    DarkGreenBlue = 49
    DarkBlue      = 11
    Indigo        = 55
    Grey80        = 56
     
    DarkRed       =  9
    Orange        = 46
    LightBrown    = 12
    Green         = 10
    GreenBlue     = 14
    Blue          =  5
    GrayBlue      = 47
    Gray50        = 16
     
    Red           =  3
    LightOrange   = 45
    LimeGreen     = 43
    MarineGreen   = 50
    WaterGreen    = 42
    LightBlue     = 41
    Violet        = 13
    Gray40        = 48
     
    Pink          =  7
    Gold          = 44
    Yellow        =  6
    BrigthGreen   =  4
    Turquoise     =  8
    SkyBlue       = 33
    Plum          = 54
    Grey25        = 15
     
    SalmonPink    = 38
    Brown         = 40
    LightYellow   = 36
    LightGreen    = 35
    LightTurquoise= 34
    MediumBlue    = 37
    Lavender      = 39
    White         =  2
     
    Set net   = Wscript.CreateObject("WScript.Network")
    Set fso   = WScript.CreateObject("Scripting.FileSystemObject")
    Set args  = Wscript.Arguments
    If args.count=0 Then
    	computer=net.ComputerName
    Else
    	computer=args(0)
    	End If
     
    Set GDict = WScript.CreateObject("Scripting.Dictionary")
    Set UDict = WScript.CreateObject("Scripting.Dictionary")
     
    Set GUset = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & Computer).InstancesOf _
    	("Win32_GroupUser")
     
    for each GU in GUset 
    	set Group=GetObject("winmgmts:" & GU.GroupComponent)
    	set User =GetObject("winmgmts:" & GU.PartComponent)
    	GName=Group.Name
    	Uname=User.Name
    	If GDict.Exists(GName) Then
    		OldList=GDict.Item(GName)
    		GDict.Item(GName)=OldList & "," & UName 
    	Else
    		GDict.Add GName, UName
    		End If 
     
    	If UDict.Exists(UName) Then
    		OldList=UDict.Item(UName)
    		UDict.Item(UName)=OldList & "," & GName 
    	Else
    		UDict.Add UName, GName
    		End If 
    	next
     
    Dim GTabG,GtabU, UTabU, UTabG
    GtabG=GDict.Keys 
    GtabU=GDict.Items 
    UtabU=UDict.Keys 
    UtabG=UDict.Items
     
    Set oXL = WScript.CreateObject("EXCEL.application")
    oXL.Visible = True
    oXL.Workbooks.Add
     
    Cellule 1,1,"Liste des  Groupes et Comptes de l'ordinateur " & Computer & " le " & FormatDateTime(now, vbLongDate),true,false,12
     
    NL=3
    Cellule NL,2,"GROUPE",true,false,10
    Cellule NL,3,"COMPTES DU GROUPE",true,false,10
    Color NL,2,NL,3,xlMedium,Grey25
    IndexCol=1
    For i = 0 To GDict.count-1
    	Members=Split(GtabU(i),",")
    	nm=Ubound(Members)
    	NL=NL+1
    	NLdeb=NL
    	Cellule NL,2,GtabG(i),true,false,8
    	If nm>=0 Then
    		For j = 0 To nm
    			If j>0 Then NL=NL+1
    			Cellule NL,3,Members(j),false,false,8
    			Next
    		End If
    	Color NLdeb,2,NL,3,xlThin,LightTurquoise
    	Next
    Color 3,2,NL,3,xlMedium,-2
    NLMax=NL
     
    NL=3
    Cellule NL,5,"COMPTE",true,false,10
    Cellule NL,6,"APPARTENANCE",true,false,10
    Color NL,5,NL,6,xlMedium,Grey25
    IndexCol=1
    For i = 0 To UDict.count-1
    	Groups=Split(UtabG(i),",")
    	ng=Ubound(Groups)
    	NL=NL+1
    	NLdeb=NL
    	Cellule NL,5,UtabU(i),true,false,8
    	If ng>=0 Then
    		For j = 0 To ng
    			If j>0 Then NL=NL+1	
    			Cellule NL,6,Groups(j),false,false,8
    			Next
    		End If
    	Color NLdeb,5,NL,6,xlThin,LightTurquoise
    	Next
    Color 3,5,NL,6,xlMedium,-2
     
    If NL>NLmax Then NLMax=NL
     
    Cellule NLMax+2,1,"JCB © 2004",false,true,8
    oXL.Columns("B:F").Select
    oXL.Selection.Columns.AutoFit
    oXL.Range("A1").Select
    ExcelFile=getpath() & "Liste des comptes de " & Computer &".xls"
    If fso.FileExists(ExcelFile) Then fso.DeleteFile ExcelFile, true 
    oXL.ActiveWorkbook.SaveAs ExcelFile
    oXL.ACtiveWorkbook.Saved = True
    Wscript.quit
    '--------------------------------------------------------------------
    Sub Cellule(NumL,NumC,chaine,casse,italic,size)
    oXL.Cells(NumL,NumC).Value = Chaine
    If casse or size<>0 Then
    	Coords=CellName(NumL,NumC)
    	oXL.Range(Coords & ":" & Coords).Select
    	If casse   Then oXL.Selection.Font.Bold = True
    	If italic  Then oXL.Selection.Font.Italic = True
    	If size<>0 Then oXL.Selection.Font.Size = size
    	End If
    End Sub
    '--------------------------------------------------------------------
    Function CellName(NumL,NumC)
    If NumC<=26 Then
    	anumc=chr(64+NumC)
    Else
    	n1=int(NumC/26)
    	n2=NumC-n1*26
    	anumc=chr(64+n1) & chr(64+n2)
    	End If
    CellName=anumc & NumL
    End Function
    '--------------------------------------------------------------------
    Sub Color(NLdeb,NCdeb,NLfin,NCfin,W,col)
    Coords1=CellName(NLdeb,NCdeb)
    Coords2=CellName(NLfin,NCfin)
    oXL.Range(Coords1 & ":" & Coords2).Select
    With oXL.Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
    	.Weight = W
        .ColorIndex = xlAutomatic
    	End With
    With oXL.Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = W
        .ColorIndex = xlAutomatic
    	End With
    With oXL.Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = W
        .ColorIndex = xlAutomatic
    	End With
    With oXL.Selection.Borders(xlEdgeRight)
    	.LineStyle = xlContinuous
        .Weight = W
        .ColorIndex = xlAutomatic
    	End With
    With oXL.Selection.Interior
    	Select Case col
    		Case -1 
    			If IndexCol=1 Then
    				.ColorIndex = LightTurquoise	
    			Else
    				.ColorIndex = LightYellow
    				End If	
    		Case -2
    		Case else
    			.ColorIndex =col
    		End Select
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
    	End With
    IndexCol=3-IndexCol
    End Sub
    '--------------------------------------------------------------------
    ' Fonction de récupération du répertoire courant
    Function GetPath()
    Dim path
    path = WScript.ScriptFullName
    GetPath = Left(path, InStrRev(path, "\"))
    End Function
    '--------------------------------------------------------------------

  3. #3
    Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2010
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2010
    Messages : 7
    Points : 3
    Points
    3
    Par défaut
    Salut,

    Merci pour ta réponse.
    Mais je ne comprend ce que le script fait au juste.
    Peut tu me le détailler ?

Discussions similaires

  1. [Sources/Macros] [PROC GCHART] Modifier l'ordre d'apparition des sous-groupes d'un diagramme en barres
    Par fafabzh6 dans le forum Contribuez
    Réponses: 0
    Dernier message: 04/08/2014, 16h00
  2. PROC GCHART Changer l'ordre d'apparition des sous-groupes
    Par Hélixe dans le forum ODS et reporting
    Réponses: 10
    Dernier message: 15/02/2012, 14h12
  3. des stats pour des sous groupes
    Par teo000 dans le forum SAS STAT
    Réponses: 3
    Dernier message: 04/06/2009, 11h07
  4. calculer des moyennes pour des sous groupes
    Par madib dans le forum SAS Base
    Réponses: 3
    Dernier message: 04/02/2009, 17h50
  5. Réponses: 3
    Dernier message: 22/09/2008, 09h35

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