Script de rapport des erreur 500 sur IIS

par | Oct 15, 2015 | PowerShell | 0 commentaires

 

Ce script génère un rapport texte des erreurs 500 en parsant les logs IIS d’une liste de serveurs. (Lien du script plus bas).

#SCRIPT REMONTANT LES OCCURENCES DES ERREURS ‘500’ DANS LES LOGS IIS DE PLUSIEURS SERVEURS #INTERVALLE DE TEMPS PAR DEFAUT: Journée d’hier ($firstdate –> $date) #MODIFIER EN FONCTION, LE COMPTE UTILISE ($cred), LE CHEMIN DU RAPPORT ($rapport), LES NOMS DES SERVEURS ($FrontServers), LE CHEMIN DES LOGS ($Logpath) # #PAR DEFAUT L’INTERVALLE DE TEMPS EST CELUI DE LA JOURNEE DE LA VEILLE. $cred= Get–Credential –Credential « MYDOMAIN\«  $rapport = « D:\Temp\error500.txt«  $date = (get–date).Date $firstdate = (get–date).Date.AddDays(–1) $FrontServers=(« SERVEUR1« ,« SERVEUR2« ,« SERVEUR3« ,« SERVEUR4« ) $Logpath=« c$\inetpub\logs\logfiles«  $Header= « ########### ERREURS 500 SUR LES FRONTAUX IIS ( $firstdate —> $date ) ############## ######################################################################################################################«  #suppression fichier rapport if (Test–Path $rapport) { Remove–Item $rapport } #ajout de l’entete au rapport $Header | Out-File –FilePath $rapport «  » | Out-File –FilePath $rapport –Append «  » | Out-File –FilePath $rapport –Append Function Get–Error500 ($Front,$cred) { #chaine 500 (!entourée de deux espaces!) $pattern=«  500 «  New–PSDrive –Name « $Front`_drive«  –Credential $cred –Root \\$Front\$Logpath –PSProvider FileSystem | Out–Null $logs= Get–ChildItem –Path « $Front`_drive:\*.log«  –Recurse | Where–Object {$_.LastWriteTime -ge $firstdate -AND $_.LastWriteTime -lt $date} | Select–Object foreach ($log in $logs) { write–host –BackgroundColor White –ForegroundColor Blue « LOG: $log«  « LOG: $log«  | Out-File $rapport –Append «  » | Out-File $rapport –Append get–content –Path $log | Select–String –Pattern $pattern | Select–Object –Property Line | Out-File $rapport –Append } Remove–PSDrive –Name « $Front`_drive«  –Force } foreach ($Front in $FrontServers) { Write–Host –ForegroundColor Yellow « —-SERVEUR $Front—- :«  « —-SERVEUR $Front—- :«  | Out-File –Append $rapport Get–Error500 –Front $Front –cred $cred Write–Host «  » Write–Host « ***************************************************************************************************************«  Write–Host «  » «  » | Out-File –Append $rapport « ***************************************************************************************************************«  | Out-File –Append $rapport «  » | Out-File –Append $rapport }

 

0 commentaires

Soumettre un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *