Soyez le premier à donner votre avis sur cette source.
Vue 5 468 fois - Téléchargée 711 fois
'OBJETS NECESSAIRES Dim WshShell, sTmp, fso, f Set updateSession = CreateObject("Microsoft.Update.Session") Set updateSearcher = updateSession.CreateUpdateSearcher() Set WshShell=CreateObject("WScript.Shell") Set fso = CreateObject("Scripting.FileSystemObject") 'FIN OBJETS NECESSAIRES 'CREATION RAPPORT Const ForAppend = 8, ForWriting = 2 sTmp = WshShell.ExpandEnvironmentStrings("%TMP%\rapport.txt") 'sTmp = "c:\tmp\rapport.txt" set f = fso.openTextFile(sTmp, ForWriting,true) 'RECUPERATION NOM SERVEUR Set WshNetwork = WScript.CreateObject("WScript.Network") NomMachine = WshNetwork.ComputerName 'FIN RECUPERATION NOM SERVEUR f.writeline(Now & " Mise à jour du serveur : " & NomMachine) f.writeline(" ") 'FIN CREATION RAPPORT 'RECHERCHE DES MISES A JOUR updateSession.ClientApplicationID = "Recherche et installation des mises à jour microsoft" WScript.Echo "Recherche des mises à jour..." & vbCRLF Set searchResult = updateSearcher.Search("IsInstalled=0 and Type='Software' and IsHidden=0") WScript.Echo "Liste des mises à jour applicables sur la machine:" 'f.writeline("- Liste des mises à jour applicables sur la machine:") For I = 0 To searchResult.Updates.Count-1 Set update = searchResult.Updates.Item(I) WScript.Echo I + 1 & "> " & update.Title ' f.writeline(" " & I + 1 & "> " & update.Title) Next 'f.writeline(" ") If searchResult.Updates.Count = 0 Then WScript.Echo "Il n'y a pas de mises à jour applicables." f.writeline(" Il n'y a pas de mises à jour applicables.") f.writeline(" ") f.close 'APPEL FONCTION ENVOI MAIL 'call SendMail("mon@mail.fr", "Rapport du serveur " & NomMachine, "Rapport de la machine " & NomMachine) WScript.Quit End If 'FIN RECHERCHE DES MISES A JOUR 'CREATION DE LA LISTE DES MISES A JOUR ET LES TELECHARGER WScript.Echo vbCRLF & "Création d'une liste des mises à jour à télécharger:" Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl") For I = 0 to searchResult.Updates.Count-1 Set update = searchResult.Updates.Item(I) addThisUpdate = false If update.InstallationBehavior.CanRequestUserInput = true Then WScript.Echo I + 1 & "> Annulée: " & update.Title & " parce qu'elle nécessite l'intervention de l'utilisateur" f.writeline("- " & update.Title & " a été annulée car elle nécessite l'intervention de l'utilisateur") Else If update.EulaAccepted = false Then update.AcceptEula() addThisUpdate = true Else addThisUpdate = true End If End If If addThisUpdate = true Then WScript.Echo I + 1 & "> Ajout: " & update.Title updatesToDownload.Add(update) End If Next If updatesToDownload.Count = 0 Then WScript.Echo "Toutes les mises à jour applicables ont été ignorés." f.writeline(" ") f.writeline("- Toutes les mises à jour applicables ont été ignorés.") f.close 'APPEL FONCTION ENVOI MAIL 'call SendMail("mon@mail.fr", "Rapport du serveur " & NomMachine, "Rapport de la machine " & NomMachine) WScript.Quit End If WScript.Echo vbCRLF & "Téléchargement des mises à jour..." Set downloader = updateSession.CreateUpdateDownloader() downloader.Updates = updatesToDownload downloader.Download() 'FIN CREATION DE LA LISTE DES MISES A JOUR ET LES TELECHARGER 'INSTALLATION DES MISES A JOURS Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl") rebootMayBeRequired = false WScript.Echo vbCRLF & "Mises à jour téléchargés avec succés:" For I = 0 To searchResult.Updates.Count-1 set update = searchResult.Updates.Item(I) If update.IsDownloaded = true Then WScript.Echo I + 1 & "> " & update.Title updatesToInstall.Add(update) If update.InstallationBehavior.RebootBehavior > 0 Then rebootMayBeRequired = true End If End If Next If updatesToInstall.Count = 0 Then WScript.Echo "Les mises à jour ne ce sont pas téléchargés." f.writeline(" ") f.writeline("- Les mises à jour ne ce sont pas téléchargés.") f.close 'APPEL FONCTION ENVOI MAIL 'call SendMail("mon@mail.fr", "Rapport du serveur " & NomMachine, "Rapport de la machine " & NomMachine) WScript.Quit End If If rebootMayBeRequired = true Then WScript.Echo vbCRLF & "Ces mises à jour peuvent nécessiter un redémarrage." End If strInput = "Y" If (strInput = "Y" or strInput = "y") Then WScript.Echo "Installation des mises à jour..." Set installer = updateSession.CreateUpdateInstaller() installer.Updates = updatesToInstall Set installationResult = installer.Install() 'RESULTAT DE L'INSTALLATION WScript.Echo "Résultat de l'installation: " & _ installationResult.ResultCode WScript.Echo "Redémarrage requis: " & installationResult.RebootRequired & vbCRLF WScript.Echo "Liste des mises à jour installées " & "et les résultats d'installation individuels:" f.writeline(" ") 'RESULTAT POUR LES MISES A JOUR INSTALLEES CORECTEMENT f.writeline("Liste des mises à jour installées : ") For I = 0 to updatesToInstall.Count - 1 If installationResult.GetUpdateResult(i).ResultCode = 2 then WScript.Echo I + 1 & "> " & _ updatesToInstall.Item(i).Title & _ ": " & installationResult.GetUpdateResult(i).ResultCode f.writeline(" " & I + 1 & "> " & updatesToInstall.Item(i).Title & ": " & installationResult.GetUpdateResult(i).ResultCode) End If Next 'RESULTAT POUR LES MISES A JOUR EN ERREUR f.writeline("Liste des mises en erreur avec leurs codes erreur : ") For I = 0 to updatesToInstall.Count - 1 If installationResult.GetUpdateResult(i).ResultCode <> 2 then WScript.Echo I + 1 & "> " & _ updatesToInstall.Item(i).Title & _ ": " & installationResult.GetUpdateResult(i).ResultCode f.writeline(" " & I + 1 & "> " & updatesToInstall.Item(i).Title & ": " & installationResult.GetUpdateResult(i).ResultCode) Set WshShell = createobject("wscript.shell") Set oExec = WshShell.Exec("SnmpTrapGen.exe -r:@IPAGENTSNMP -v:1 -c:""public"" -to:.1.3.6.1.2.1.1.1.0") End If Next 'FIN RESULTAT DE L'INSTALLATION End If 'FIN INSTALLATION DES MISES A JOURS f.close 'APPEL FONCTION ENVOI MAIL 'call SendMail("mon@mail.fr", "Rapport du serveur " & NomMachine, "Rapport de la machine " & NomMachine) 'REDEMARRAGE DE LA MACHINE 'If installationResult.RebootRequired = true then ' Set objShell = CreateObject("WScript.Shell") ' objShell.run "shutdown -t 5 -r" 'End If 'FIN REDEMARRAGE DE LA MACHINE 'FIN DU SCRIPT 'FONCTION ENVOI MAIL Function SendMail(strTo, strBody, strTitre) Dim WshShell, sTmp Set WshShell=CreateObject("WScript.Shell") sTmp = WshShell.ExpandEnvironmentStrings("%TMP%\rapport.txt") Set objMail = CreateObject("CDO.Message") Set objConfig = CreateObject("CDO.configuration") Set objFields = objConfig.Fields With objFields .Item("http://schemas.microsoft.com/cdo/configuration/SendUsing")= 2 'Définit le type d'envoi en SMTP .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")= "mon.serveurmail.fr" 'Serveur de mail .Item("http://schemas.microsoft.com/cdo/configuration/SMTPServerPort")= 25 'Port du serveur smtp .Update End With With objMail Set .Configuration = objConfig .To = strTo 'adresse destinataire .Cc = strCc .Bcc = strBcc .AddAttachment(sTmp) 'Piece jointe .From = "updateserver" & NomMachine & "@mon.domaine.fr" 'adresse expéditeur .Subject = strTitre 'Objet .HTMLBody = strBody 'Corp du message .Send End With End Function 'FIN FONCTION ENVOI MAIL
Ton script est adopté (par moi en tout cas) donc merci.
Mais pour le développement je met 8 et pas moins, car c'est propre, documenté et bien pensé.
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.