kerberos69
Messages postés21Date d'inscriptionmercredi 6 avril 2005StatutMembreDernière intervention 9 juillet 2008
-
9 juil. 2008 à 10:25
cs_Tayn
Messages postés1Date d'inscriptionjeudi 22 février 2007StatutMembreDernière intervention14 janvier 2009
-
14 janv. 2009 à 15:08
bonjour,
j'ai crée ce script afin de lister les shares non administratifs et les permissions NTFS d'un ou de plusieurs serveurs, a partir d'un fichier texte.
il fonctionne a merveille lorsque je l'utilise en local (c'est a dire que dans le fichier de reference j'indique le nom de mon poste de travail), mais il me mets une erreur sur la ligne 131 lorsque je fais de la requete WMI distante sur "Win32_LogicalFileSecuritySetting".
je precise que dans ce cas, j'execute le script sous une session "domain admin" qui est lui meme admin local des serveurs distants...
bref je pense que c'est un pb de syntaxe mais je n'y arrive pas...
pouvez -vous m'apporter votre aide svp ?
merci d'avance
' Objet de ce script
' Lister les Partages non-administratifs d'un ou plusieurs serveurs
' Pour chacun, énumération des autorisation de partage et des acces NTFS
'
'
'
'
'-----------------------------------------------'
'DEBUT DU SCRIPT
'-----------------------------------------------'
'Declaration des variables
Dim InputFile, objFSO, objTextFile, strComputer
Dim strWMIQuery, objWMI, colItems
Dim Share, objWMIsvc, wmiShareSec
'
' Recupération de la liste des serveurs a interroger
InputFile = "D:\servers.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
Set objWMIsvc = GetObject("winmgmts:" & "\" & strComputer & "\root\cimv2")
Set wmiShareSec = objWMIsvc.get("Win32_LogicalShareSecuritySetting.Name='" & Share.Name & "'")
NL=NL+1
' memo ligne deb'
memoNL = NL
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
NL = memoNL
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
'-----------------------------------------------'
'Fin de mise en forme du tableau EXCEL'
'-----------------------------------------------'
oXL.Sheets(1).Select
oXL.Sheets(1).Name = "ListShares"
'oXL.Sheets(2).Select
'oXL.Sheets(2).Name = "Informations"
oXL.Sheets(1).Activate
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
WScript.Echo ("Audit Complet!")
'-----------------------------------------------'
'FIN DU SCRIPT
'-----------------------------------------------'
A voir également:
Probleme acces WMI distant et Win32_LogicalFileSecuritySetting.path
Kristof_Koder
Messages postés918Date d'inscriptionvendredi 3 août 2007StatutMembreDernière intervention27 octobre 200810 9 juil. 2008 à 13:02
Je suppose que c'est sur cette ligne que tu as un souci ...
Set objWMIsvc = GetObject("winmgmts:" & "\" & strComputer & "\root\cimv2")
Donc, essaye en mettant cela à la place :
Set objWMIsvc = GetObject("winmgmts:{impersonationLevel=Impersonate}!\" & strComputer & "\root\cimv2")
kerberos69
Messages postés21Date d'inscriptionmercredi 6 avril 2005StatutMembreDernière intervention 9 juillet 2008 9 juil. 2008 à 21:57
bonjour et merci de ta réponse.
j'essaierais d'integrer ton idée dans ton script mais il me semble avoir compris que la chaine{impersonationLevel=Impersonate} permettait aux objets d'utiliser les informations d'ouverture de session de l'appelant. Vu que j'execute le script en tant que domain admin, je ne devrais pas rencontrer de permissions.
Mon erreur se produit sur la ligne suivante :
Set wmiFileSecSetting = GetObject("winmgmts:Win32_LogicalFileSecuritySetting.path='" & Share.Path &"'")
et je reste persuadé d'une erreur de syntaxe... je vais perseverer et aussi tenter ta méthode.. merci