Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ServerListFile = "ErrorLog.txt"
- $ServerList = Get-Content $ServerListFile
- $Result = @()
- $user= whoami
- $date = (get-Date).tostring()
- $excel = New-Object -ComObject Excel.Application
- $workbook = $excel.Workbooks.add()
- $excel.visible = $true
- $s1 = $workbook.sheets | where {$_.name -eq 'Sheet1'}
- $s1.Delete()
- $s3 = $workbook.sheets | where {$_.name -eq 'Sheet3'}
- $s3.Delete()
- $s2 = $workbook.sheets | where {$_.name -eq 'Sheet2'}
- $s2.name = "Ping Result"
- $cells= $s2.Cells
- $s2.range("A2:A2").cells="Hostname"
- $s2.range("A2:A2").font.bold = "true"
- $s2.range("A2:A2").interior.colorindex=48
- $s2.range("A2:A2").HorizontalAlignment = -4108
- $s2.range("B2:B2").cells="Ping Result"
- $s2.range("B2:B2").font.bold = "true"
- $s2.range("B2:B2").interior.colorindex=48
- $s2.range("B2:B2").HorizontalAlignment = -4108
- $s2.range("C2:C2").cells="LocalAdmin Info"
- $s2.range("C2:C2").font.bold = "true"
- $s2.range("C2:C2").interior.colorindex=48
- $s2.range("C2:C2").HorizontalAlignment = -4108
- $s2.range("A3:c3").EntireColumn.autofit() | out-Null
- $row=3
- $col1=1
- $col2=2
- $col3=3
- $s2.Cells.EntireColumn.AutoFilter()
- write-host "generating"
- ForEach($computername in $ServerList)
- {
- if (test-Connection -ComputerName $computername -Count 3 -Quiet)
- {
- $cells.item($row,$col1)=$computername
- $cells.item($row,$col2)=" Server is alive and pinging"
- $cells.item($row,$col3)= "local admin info here..."
- }
- else
- {
- $cells.item($row,$col1)=$computername
- $cells.item($row,$col1).Interior.ColorIndex = 46
- $cells.item($row,$col2)="Server seems dead not pinging"
- $cells.item($row,$col3)= "Local Admin Not Available"
- $cells.item($row,$col2).Interior.ColorIndex = 46
- $cells.item($row,$col3).Interior.ColorIndex = 46
- }
- $row++
- $col1=1
- $col2=2
- $s2.range("A3:c3").EntireColumn.autofit() | out-Null
- }
- $row=$row+2
- write-host "Script Completed !!!"
- "`n"
- $workbook.SaveAs("$env:userprofiledesktopMultiple_Ping_Test.xlsx")
Add Comment
Please, Sign In to add comment