• Home
  • About 404TS
  • Contact

404 Tech Support

Where IT Help is Found

  • Articles
    • Code
    • Entertainment
    • Going Green
    • Hardware, Gadgets, and Products
    • Management
    • Network
    • News
    • Operating Systems
    • Security and Privacy
    • Software
    • System Administration
    • Talking Points
    • Tech Solutions
    • Web
    • Webmaster
  • Reviews
  • Media
    • Infographics
    • Videos
  • Tech Events
  • Tools
    • How do I find my IP address?
    • Browser and plugin tests
  • Get a Technical Consultation
You are here: Home / Articles / Code / PowerShell script to ping multiple computers

PowerShell script to ping multiple computers

2015-03-23

A recent project involved tracking down some old computers. To find them, we only had the computer name to start. We came up with a plan to try to find out more information about the computers by accessing the hidden C$ share on the computers. This quickly became time-consuming and frustrating as many of the computers were not even pingable, as they were most likely not powered on at the time we were trying to connect to them.

To speed things up, we could ping each computer first and only try the more time-consuming C$ share approach to those that responded to the ping. Since these computers might be powered on at different times of the day, a script made the most sense to save from typing everything out each time.

This PowerShell script reads from a text file ping.txt with each computer name on its own line and then uses test-connection to ping the computer. Ping.txt should reside in the same folder as the script. The computers that are successfully pinged are pinged one more time to get their IP address (more information to use in tracking them down) and are logged in a text file to the desktop as text file named pingable_[timestamp]. The computers that do not reply to the ping are logged to a text file on the desktop named notpingable_timestamp.

I considered making it a circular log so the non-responding computers would be filtered and ready for the next round of running the script but kept with this direction to keep things more straight-forward.

Note to replace .domain.fqdn with your own fully qualified domain name, so it is appended to each computer name.

# Jason Hamilton
# https://www.404TechSupport.com/
# Ping a number of computers and report the successful ones.

# List computer name (not FQDN) in ping.txt in the same directory as this script
$ScriptPath = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
Write-Host $ScriptPath
$PCs = Get-Content $ScriptPathping.txt
$timestamp = get-date -f "MMddyyyyHHmm"
$successlog = [string]::concat($Env:userprofile, "Desktoppingable_", $timestamp,".txt")
$faillog = [string]::concat($Env:userprofile, "Desktopnotpingable_", $timestamp,".txt")
Clear-host
Write-Host "Testing connection to computers listed in ping.txt"
Write-Host ""

# loop through above array of each computer and test pinging to them.
Foreach ($i in $PCs)
{
$PC = $i+".domain.fqdn"

$pingable = test-connection -ComputerName $PC -Count 2 -quiet

if ($pingable) {
$pingable2 = test-connection -ComputerName $PC -Count 1

#List successful connections
Write-Host $PC "is pingable with" $pingable2.IPV4Address
$report = [string]::concat($PC, " is pingable with ", $pingable2.IPV4Address)
$report | Out-File -FilePath $successlog -Append

} else {
Write-Host $PC "was not pingable."
$report = [string]::concat($PC, " was not pingable.")
$report | Out-File -FilePath $faillog -Append
}
}

Write-Host ""
#Equivalent to Pause
Read-Host 'Press Enter to continue...' | Out-Null

After the script completes going through the list of computers, you would be able to take the pingable text file and connect to those C$ shares and drill down to the user profile folder to find out who has logged in to the computer recently and hopefully help locate the computer.

Filed Under: Code

Trending

  • Product Review: Garmin Forerunner 405CX GPS Watch
    In Hardware, Gadgets, and Products, Reviews
  • McAfee Nukes Windows XP Computers World-Wide
    In Security and Privacy, Software, System Administration, Tech Solutions
  • Progress in Congress With “The Threat of Data Theft to American Consumers” Hearing Today
    In News, Security and Privacy

Latest Media Posts

Multifunctional Video Conversion Tools – Wondershare Video Converter

Multifunctional Video Conversion Tools – Wondershare Video Converter

The WannaCry Post-Mortem

The WannaCry Post-Mortem

  • Popular
  • Latest
  • Today Week Month All
  • Microsoft Word: “This modification is not allowed because the selection is locked.” Microsoft Word: "This modification is not allowed because the selection is locked."
  • How to edit the message subject in Outlook 2016 How to edit the message subject in Outlook 2016
  • What is the AllJoyn Router Service on Windows 10? What is the AllJoyn Router Service on Windows 10?
  • Increase IIS Private Memory Limit to improve WSUS availability Increase IIS Private Memory Limit to improve WSUS availability
  • Scan-To-Email with Office 365 from a multifunction copier or printer Scan-To-Email with Office 365 from a multifunction copier or printer
  • 5 Factors To Look At When Choosing Web Hosting 5 Factors To Look At When Choosing Web Hosting
  • How managers can improve their team’s written communication skills How managers can improve their team’s written communication skills
  • Online Casino Technology – How Does It All Work? Online Casino Technology – How Does It All Work?
  • Virtual Assistant Devices Will Reshape Your Life in 2019 Virtual Assistant Devices Will Reshape Your Life in 2019
  • The 5 Most Common Problems with PC Gaming The 5 Most Common Problems with PC Gaming
Ajax spinner

Upcoming Tech Events

There are no upcoming events at this time.

Elevator Pitch

404 Tech Support documents solutions to IT problems, shares worthwhile software and websites, and reviews hardware, consumer electronics, and technology-related books.

Subscribe to 404TS articles by email.

Follow Us

  • Facebook
  • Google+
  • RSS
  • Twitter
  • YouTube

Recent Posts

  • 5 Factors To Look At When Choosing Web Hosting
  • How managers can improve their team’s written communication skills
  • Online Casino Technology – How Does It All Work?

Search

FTC Disclaimer

404TechSupport is an Amazon.com affiliate; when you click on an Amazon link from 404TS, the site gets a cut of the proceeds from whatever you buy. This site also uses Skimlinks for smart monetization of other affiliate links.
Use of this site requires displaying and viewing ads as they are presented.

Copyright © 2019 · 404TechSupport.com