PowerShell – Ping Machines and report in Excel

Hi Readers,

Today I am sharing a old script that I have shared before at :

https://github.com/VikasSukhija/Downloads/blob/master/excelping.vbs

It was earlier written in VBscript & now has been converted to PowerShell.

This script reads from text file (name of machines – MachineList.txt) , pings them & returns status (up or down).

Extract the Zip file from below link , update the MachineList.txt

https://github.com/VikasSukhija/Downloads/blob/master/excelping.zip

 

MachineList.txt file..

 

Just double click the batch file, below will be the result.

 

Pls rate the script if it worked for you.

################################################################### 
##           Script to check the status of machines               
##           Author: Vikas Sukhija                                    
##           Date: 01-28-2016                                
##           Update:  Converted from VBscript 
##https://gallery.technet.microsoft.com/scriptcenter/Ping-Machines-and-report-19d590ce           
################################################################### 
 
$path = ".\results.xls" 
 
$objExcel = new-object -comobject excel.application  
 
if (Test-Path $path)  
{  
$objWorkbook = $objExcel.WorkBooks.Open($path)  
$objWorksheet = $objWorkbook.Worksheets.Item(1)  
} 
 
else {  
$objWorkbook = $objExcel.Workbooks.Add()  
$objWorksheet = $objWorkbook.Worksheets.Item(1) 
} 
 
$objExcel.Visible = $True 
 
#########Add Header#### 
 
$objWorksheet.Cells.Item(1, 1) = "MachineName" 
$objWorksheet.Cells.Item(1, 2) = "Result" 
 
$machines = gc .\machinelist.txt 
$count = $machines.count 
 
$row=2 
 
$machines | foreach-object{ 
$ping=$null 
$machine = $_ 
$ping = Test-Connection $machine -Count 1 -ea silentlycontinue 
 
if($ping){ 
 
$objWorksheet.Cells.Item($row,1) = $machine 
$objWorksheet.Cells.Item($row,2) = "UP" 
 
$row++else { 
 
$objWorksheet.Cells.Item($row,1) = $machine 
$objWorksheet.Cells.Item($row,2) = "DOWN" 
 
$row++} 
} 
 
# Format the excel 
  
# To wrap the text            
$d = $objWorksheet.UsedRange  
$null = $d.EntireColumn.AutoFit() 
 
##to set column width and cell alignment 
$objWorksheet.Columns.Item(1).columnWidth = 24 
$objWorksheet.Columns.Item(2).columnWidth = 24 
$objWorksheet.Columns.HorizontalAlignment = -4131 
$objWorksheet.rows.item(1).Font.Bold = $True  
 
##to apply filter 
$headerRange = $objWorksheet.Range("a1","n1"$headerRange.AutoFilter() | Out-Null 
#################################################################

Tech Wizard

https://techwizard.cloud

https://syscloudpro.com/

 

3 thoughts on “PowerShell – Ping Machines and report in Excel

  1. Pingback: PowerShell – IP to HostName along with Ping in Excel | Microsoft Technologies Blog

  2. Pingback: PowerShell – HostName to IP along with Ping in Excel | Microsoft Technologies Blog

  3. Pingback: PowerShell – IP to HostName along with Ping in Excel | Tech Wizard

Leave a comment