Find hard disk bad sectors (error 7) if exist on remote computers - Script 2017



This is one great script to find bad sectors if exist on remote computers list.

#Format Excel sheet

[System.Threading.Thread]::CurrentThread.CurrentCulture = New-Object "System.Globalization.CultureInfo" "en-US"
$objExcel = New-Object -comobject Excel.Application
 $objExcel.visible = $True
 $objWorkbook = $objExcel.Workbooks.Add()
 $objSheet = $objWorkbook.Worksheets.Item(1)
 $objSheet.Cells.Item(1,1) = "Server"
 $objSheet.Cells.Item(1,2) = "LogName"
 $objSheet.Cells.Item(1,3) = "EventID"
 $objSheet.Cells.Item(1,4) = "Date"
 $objSheet.Cells.Item(1,5) = "Message"
 $objSheetFormat = $objSheet.UsedRange
 $objSheetFormat.Interior.ColorIndex = 19
 $objSheetFormat.Font.ColorIndex = 11
 $objSheetFormat.Font.Bold = $True

$row = 1

$servers = gc C:\Users\YOUR USERNAME\Desktop\machines.txt

foreach ($server in $servers)
 {
 $row = $row + 1
 $objSheet.Cells.Item($row,1).Font.Bold = $True
 $objSheet.Cells.Item($row,1) = $server
$AppLog = Get-EventLog -LogName System -EntryType Error -computer $server -Newest 30 | Where-Object {$_.EventId -eq ’7’}
$row = $row + 1
 $objSheet.Cells.Item($row,1).Font.Bold = $True
 $objSheet.Cells.Item($row,2) = 'System'
 foreach ($AppEvent in $AppLog)
 {
 $row = $row + 1
 $objSheet.Cells.Item($row,3) = $AppEvent.EventID
 $objSheet.Cells.Item($row,4) = $AppEvent.TimeGenerated
 $objSheet.Cells.Item($row,5) = $AppEvent.Source
 $objSheet.Cells.Item($row,6) = $AppEvent.Message
 }
}

$objSheetFormat = $objSheet.UsedRange
 $objSheetFormat.EntireColumn.AutoFit()
 $objSheetFormat.RowHeight = 15

User can change values in this place in script:

{$_.EventId -eq ’7’}  - number 7 is event number for bad sectors and user can replace this number with any event number from event viewer which means that the script can be used to retrieve any problems - only for errors (red event logs).

User must be local administrator on all remote computers in computer list.
If user with this script don't find anything that is great news but if result in excel contains event 7 logs that is problem for single computer.



Share this

Related Posts

1 komentari :

komentari