Guest User

Untitled

a guest
Jan 23rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. $ServerListFile = "ErrorLog.txt"
  2. $ServerList = Get-Content $ServerListFile
  3. $Result = @()
  4. $user= whoami
  5. $date = (get-Date).tostring()
  6. $excel = New-Object -ComObject Excel.Application
  7. $workbook = $excel.Workbooks.add()
  8. $excel.visible = $true
  9. $s1 = $workbook.sheets | where {$_.name -eq 'Sheet1'}
  10. $s1.Delete()
  11. $s3 = $workbook.sheets | where {$_.name -eq 'Sheet3'}
  12. $s3.Delete()
  13. $s2 = $workbook.sheets | where {$_.name -eq 'Sheet2'}
  14. $s2.name = "Ping Result"
  15. $cells= $s2.Cells
  16. $s2.range("A2:A2").cells="Hostname"
  17. $s2.range("A2:A2").font.bold = "true"
  18. $s2.range("A2:A2").interior.colorindex=48
  19. $s2.range("A2:A2").HorizontalAlignment = -4108
  20. $s2.range("B2:B2").cells="Ping Result"
  21. $s2.range("B2:B2").font.bold = "true"
  22. $s2.range("B2:B2").interior.colorindex=48
  23. $s2.range("B2:B2").HorizontalAlignment = -4108
  24. $s2.range("C2:C2").cells="LocalAdmin Info"
  25. $s2.range("C2:C2").font.bold = "true"
  26. $s2.range("C2:C2").interior.colorindex=48
  27. $s2.range("C2:C2").HorizontalAlignment = -4108
  28. $s2.range("A3:c3").EntireColumn.autofit() | out-Null
  29. $row=3
  30. $col1=1
  31. $col2=2
  32. $col3=3
  33. $s2.Cells.EntireColumn.AutoFilter()
  34. write-host "generating"
  35. ForEach($computername in $ServerList)
  36. {
  37. if (test-Connection -ComputerName $computername -Count 3 -Quiet)
  38. {
  39. $cells.item($row,$col1)=$computername
  40. $cells.item($row,$col2)=" Server is alive and pinging"
  41. $cells.item($row,$col3)= "local admin info here..."
  42.  
  43.  
  44. }
  45. else
  46. {
  47. $cells.item($row,$col1)=$computername
  48. $cells.item($row,$col1).Interior.ColorIndex = 46
  49. $cells.item($row,$col2)="Server seems dead not pinging"
  50. $cells.item($row,$col3)= "Local Admin Not Available"
  51. $cells.item($row,$col2).Interior.ColorIndex = 46
  52. $cells.item($row,$col3).Interior.ColorIndex = 46
  53. }
  54. $row++
  55. $col1=1
  56. $col2=2
  57. $s2.range("A3:c3").EntireColumn.autofit() | out-Null
  58. }
  59. $row=$row+2
  60. write-host "Script Completed !!!"
  61. "`n"
  62. $workbook.SaveAs("$env:userprofiledesktopMultiple_Ping_Test.xlsx")
Add Comment
Please, Sign In to add comment