Browse
Tools
Categories

Testing Device Access using Ping Script

Reference Number: AA-01384 Views: 1761 Last Updated: 04-25-2024 01:50 PM 0 Rating/ Voters

It is sometimes helpful to identify IP addresses that can or cannot be pinged. This article describes how to use PowerShell to ping devices and identify those that respond successfully and those that do not.

  • Extract the content of the zip file attached at the bottom of this article.
  • Edit the ipaddresses.txt file
  • Edit the file paths in PingScript.ps1 and save the file
  • Open PowerShell as administrator
  • Set the Execution policy
  • Run PingScript.ps1


Edit PowerShell Script

Open the PingScript.ps1 file and edit the location of the ipaddresses.txt file and the location where the results file is stored.

$ipList = "C:\Users\Ken\Desktop\PingScript\ipaddresses.txt"

$outputCsv = "C:\Users\Ken\Desktop\PingScript\ping_results.csv"


Edit IP Address File

The ipaddresses.txt file contains a list of IP addresses that the script will ping. Open this file in Notepad and enter your IP addresses, one per line, and save the file. The entries can be IP addresses or DNS names.

ipaddresses.txt file content. One IP address or DNS name per line

10.0.3.84
172.16.5.5
prot3fj.agent.com
netaphor.com
10.0.1.237

Pinging IP Addresses

Once ready, run the PingScript.ps1 from an elevated PowerShell prompt as shown below. The script shows each address as it is being pinged and stores the result of the operation in the ping_results.txt file.

It may be necessary to set the execution policy to run PingScript.ps1. Execute the following command from an elevated PowerShell window for all [a]:
Set-ExecutionPolicy Unrestricted


Review Results

Once the PingScript.ps1 completes execution, open the output file to observe the results. The example below illustrates that each IP address, status, and latency are displayed.


Download the attached file and edit to test ping in your environment.


Attachments
PingScript.zip 1 Kb Download File