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
|
SourceDir = "c:\temp" 'repertoire du fichier source
SourceFile = SourceDir & "\PCscan.txt" 'definissez les noms de machines a scanner dans ce fichier,
'les noms de machines ne sont pas précédés de backslash, ex :
' pc049
' pc035
Const ForReading = 1
Dim f, ws
Dim i
Dim sExcelPath
Const cdoSendUsingMethod = "http://schemas.microsoft.com/cdo/configuration/sendusing", _
cdoSendUsingPort = 2, _
cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Set ws = CreateObject ("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
'Pour Mail :
strMailto = "Email@Destinataire"
strMailFrom = "Email@Emetteur"
strSubject = "Liste des Admins de leur poste"
strSMTPServer = "IP SMTP Server"
'definition de l'emplacement de la feuille excel de sortie
sExcelPath = "C:\temp\sortieadmin.xls"
If CheckFileExists(SourceFile) Then
'Si fichier source trouvé on continue le traitement
Else
'si aucun fichier source n'est trouvé alors on affiche un popup pour le dire et on sort
msgbox ("Fichier source non trouvé -> " & SourceFile)
wscript.quit
End If
'Preparation de la feuille excel de sortie
Set oExcel = CreateObject("Excel.Application")
oExcel.Workbooks.Add
oExcel.ActiveWorkbook.Worksheets.Add
Set oSheet = oExcel.ActiveWorkbook.Worksheets(1)
oSheet.Cells.Font.Size = 10
oSheet.Name = "Administrateur"
oSheet.Cells(1,1).Value = "Machine"
oSheet.Cells(1,2).Value = "Fait Parti du groupe Administrateurs"
oSheet.Cells(1,1).Font.Bold = True
oSheet.Cells(1,1).Font.Size = 12
oSheet.Range("A1:B1").Font.Bold = True
oSheet.Range("A1:B1").Interior.Color = RGB(192,192,192)
oSheet.Cells(1,1).ColumnWidth = 25
oSheet.Cells(1,2).ColumnWidth = 35
'Debut lecture fichier source
Set f = ws.OpenTextFile (SourceFile, ForReading, True)
i = 2
Do While f.AtEndOfStream <> True
If f.AtEndOfStream <> True Then
strComputer = f.ReadLine 'on definit strcomputer avec un nom de machine
On Error Resume Next
'on definit un tableau des groupes de la machine en question
Set colGroups = GetObject("WinNT://" & strComputer & "")
colGroups.Filter = Array("group")
'on ne vas traiter que le groupe Administrateurs
For Each objGroup In colGroups
If objGroup.Name = "Administrateurs" Then
oSheet.Cells(i,1).Value = strComputer
For Each objUser in objGroup.Members
'on exclut les membres automatiques du groupe Administrateurs
if (objUser.Name <> "Administrateur" And objUser.Name <> "Domain Admins") then
oSheet.Cells(i,2).Value = objUser.Name
i = i+1
else
end if
Next
Else
End If
Next
end if
loop
'Permet de supprimer le dernier nom machine si celui-ci n'as pas de personnes particulières
'dans son groupe Administrateurs
oSheet.Cells(i,1).Value = ""
' Enregistrer feuille excel et fermer
oExcel.ActiveWorkbook.SaveAs sExcelPath
oExcel.ActiveWorkbook.Close
Set oSheet = Nothing
Set oExcel = Nothing
Set oAdsObj = Nothing
call EmailFile
'averti que le script est terminé
'msgbox ("fin du script admin")
'_________________________________________________________________________________
'Function CheckFileExists - to see if file exists '#
'______________________________________________ '#
Function CheckFileExists(sFileName) '#
'#
Dim FileSystemObject '#
'#
Set FileSystemObject = CreateObject("Scripting.FileSystemObject") '#
'#
If (FileSystemObject.FileExists(sFileName)) Then '#
CheckFileExists = True '#
Else '#
CheckFileExists = False '#
End If '#
'#
Set FileSystemObject = Nothing '#
'#
End Function '#
'_______________________________________________________________________________'#
'_________________________________________________________________________________
'Function EmailFile - Send file by E-mail '#
'______________________________________________ '#
Function EmailFile '#
Dim iMsg, iConf, Flds '#
'#
'CDO Connection '#
Set iMsg = CreateObject("CDO.Message") '#
Set iConf = CreateObject("CDO.Configuration") '#
Set Flds = iConf.Fields '#
'#
'Configuration du SMTP '#
With Flds '#
.Item(cdoSendUsingMethod) = cdoSendUsingPort '#
'#
'propriétés du serveur SMTP '#
.Item(cdoSMTPServer) = strSMTPServer '#
.Update '#
End With '#
'#
'propriétés du message '#
With iMsg '#
Set .Configuration = iConf '#
.To = strMailTo '#
.From = strMailFrom '#
.Subject = strSubject '#
End With '#
'#
'Pour attacher le fichier au mail '#
iMsg.AddAttachment ("C:\temp\sortieadmin.xls") '#
iMsg.AddAttachment ("C:\temp\PCscan.txt") '#
'#
'#
'Envoyer le message '#
iMsg.Send ' send the message. '#
'#
'#
End Function '#
'_______________________________________________________________________________'#
'By ¤FriX¤ - Code Source Libre |
Partager