salut a tous,

ci dessous le code qui permet, sur une machine presente dans un fichier texte, de lister tous ses shares non-administratifs, et d'afficher dans un fichier excel les autorisation de partage et NTFS.

si vous voulez tester, il faut creer un fichier texte dans lequel vous pouvez mettre le nom de votre machine. Il faut aussi avoir des partages presents.

j'ai juste un petit souci que je ne sais pas contourner. Si dans le 1er partage il y'a plus d'une autorisation, cela cree autant de lignes dans mon fichier excel, MAIS les autorisations NTFS s'inscrivent a la suite de la derniere ligne des autorisations de partage, d'ou un decalage avec saut de ligne systematique.

Si vous comprenez rien a mon probleme (j'arrive pas trop a l'expliquer en fait ^^), testez mon script. il plante si l'ordinateur cible est un windows 2000. il y'a un KB chez Microsoft KB321201

Merci de vos aides

PS : soyez indulgent par rapport a l'architecture du script, je ne suis pas developpeur ;-)

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
' shares sur serveurs et NTFS permissions
'-----------------------------------------------'
'           DEBUT DU SCRIPT
'-----------------------------------------------'
 
InputFile = "E:\serveurs.txt" 
 
 
Const ForReading = 1 
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(InputFile) Then
 Set objTextFile = objFSO.OpenTextFile(Inputfile,ForReading) 
 
 Do Until objTextFile.AtEndOfStream
      Redim Preserve aFileServerLine(i)
      aFileServerLine(i) = objTextFile.ReadLine
      i = i + 1
 Loop
End If
objTextFile.Close 
 
For i = 0 To UBound(aFileServerLine)
    strComputer = aFileServerLine(i)
 strWMIQuery = "SELECT * FROM Win32_Share where type ='0'"
 Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 Set colItems = objWMI.ExecQuery(strWMIQuery)
 
 
 
Next 
 
 
 
'-----------------------------------------------'
'Initialisation du tableau EXCEL'
'-----------------------------------------------' 
 
Set oXL = WScript.CreateObject("EXCEL.application")
oXL.Visible = True
oXL.screenupdating=true
oXL.Workbooks.Add
oXL.Cells.Select
With oXL.Selection.Font
 .Name = "Tahoma"
    .Size = 8
End With 
 
oXL.Cells(1,1).Value = "Liste des Partages"
oXL.Range("A1").Select
With oXL.Selection.Font
        .Name = "Tahoma"
        .Size = 12
End With 
 
NL=2 
 
oXL.Cells(NL,1).Value = "SERVEUR"
oXL.Cells(NL,2).Value = "Partage"
oXL.Cells(NL,3).Value = "Acces au partage"
oXL.Cells(NL,4).Value = "Type"
oXL.Cells(NL,5).Value = "Droits"
oXL.Cells(NL,6).Value = "Ont une permission NTFS"
oXL.Cells(NL,7).Value = "Type d'acces NTFS"
oXL.Cells(NL,8).Value = "Droits NTFS" 
 
oXL.Range("A2:H2").Select
oXL.Selection.Font.Bold = True
oXL.Selection.Interior.ColorIndex = 37 
 
 
'-----------------------------------------------'
'-----------------------------------------------'
'-----------------------------------------------'
'-----------------------------------------------' 
 
For Each Share In colItems
 
        Set objWMIsvc = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
                Set wmiShareSec = objWMIsvc.get("Win32_LogicalShareSecuritySetting.Name='" & Share.Name & "'")
                NL=NL+1
                oXL.Cells(NL,1).Value = strComputer
                oXL.Cells(NL,2).Value = Share.Name              
                RetVal = wmiShareSec.GetSecurityDescriptor(wmiSecurityDescriptor)
                DACL = wmiSecurityDescriptor.DACL
                nbwmiACE = 0
                        For Each wmiACE In DACL
                        nbwmiACE = nbwmiACE +1
                           If nbwmiACE > 1 Then
                           NL=NL+1 
                           End If
                                Set Trustee = wmiACE.Trustee                
                oXL.Cells(NL,3).Value = Trustee.Domain & "\" & Trustee.Name
                                AceType = wmiACE.AceType
                                        Select Case Int(wmiACE.AceType)
                                                Case 0 PermType = "Allow"
                                                Case 1 PermType = "Deny"
                                        End Select
                oXL.Cells(NL,4).Value = PermType                        
                                        Select Case Int(wmiACE.AccessMask)
                                                Case 1179817 SharePerm = "Read"
                                                Case 1245631 SharePerm = "Change"
                                                Case 2032127 SharePerm = "Full Control"
                                                Case Else SharePerm = "Access Mask " & wmiACE.AccessMask
                                        End Select
                oXL.Cells(NL,5).Value = SharePerm                       
                        Next 
 
 
  Set wmiFileSecSetting = GetObject("winmgmts:Win32_LogicalFileSecuritySetting.path='" & Share.Path & "'")
  RetVal = wmiFileSecSetting.GetSecurityDescriptor(wmiSecurityDescriptor)
  DACL = wmiSecurityDescriptor.DACL
 
  nbwmiFACE = 0           
             For each wmiAce in DACL
    nbwmiFACE = nbwmiFACE +1
     If nbwmiFACE > 1 Then
                    NL=NL+1                  
                 End If
                 Set Trustee = wmiACE.Trustee
    Select Case wmiAce.AceType
     Case 0
      Acetype = "Allow"
     Case 1 
     AceType = "Deny"
    End Select
  oXL.Cells(NL,6).Value = Trustee.Domain & "\" & Trustee.Name
  oXL.Cells(NL,7).Value = PermType 
    Select Case wmiAce.AccessMask
     Case 2032127
      AccessMask = "Full Control"
     Case 1245631 
     AccessMask = "Modify"
     Case 1179817 
     AccessMask = "Read"
     Case Else 
     AccessMask = "Autorisations Speciales"
    End Select
  oXL.Cells(NL,8).Value = AccessMask 
 
    Next 
 
 
Next
 WScript.Echo ("Audit Complete!") 
 
'-----------------------------------------------'
'Fin de mise en forme du tableau EXCEL'
'-----------------------------------------------' 
 
oXL.screenupdating= True 
 
oXL.Columns("A:H").Select
oXL.Selection.Columns.AutoFit 
 
oXL.Range("B3").Select
oXL.ActiveWindow.FreezePanes = True 
 
oXL.Sheets(1).Select
oXL.Sheets(1).Name = "ListShares"
oXL.DisplayAlerts = False
if oXL.Sheets.count > 1 then
 compteur = oXL.Sheets.count
 for i = compteur to 2 step -1
  oXL.Sheets(i).delete
 next
end if 
 
'-----------------------------------------------'
'FIN DU SCRIPT
'-----------------------------------------------'