Link to home
Start Free TrialLog in
Avatar of Jose Colmenares
Jose ColmenaresFlag for Chile

asked on

How to check if 5000 computers are UP?

Hi all,

I need to know if 5000 computers on a list .csv are UP?

Which command can i use?

I have this but is for only one computer.

Test-Connection -BufferSize 32 -Count 1 -ComputerName 192.168.0.41 -Quiet

Can you help me?
Avatar of Alessio P.
Alessio P.

<#

.SYNOPSIS
  Powershell script to ping all IP addresseses in a CSV file.
 
.DESCRIPTION
  This PowerShell script reads a CSV file and pings all the IP addresses listed in the IPAddress column.
 
.PARAMETER <csvfile>
   File name and path of the CSV file to read.
 
.NOTES
  Version:        1.0
   
.EXAMPLE
  Ping-IPList c:\IPaddressList.csv
   
#>

Param(
  [Parameter(Mandatory=$true, position=0)][string]$csvfile
)

$ColumnHeader = "IPaddress"

Write-Host "Reading file" $csvfile
$ipaddresses = import-csv $csvfile | select-object $ColumnHeader

Write-Host "Started Pinging.."
foreach( $ip in $ipaddresses) {
    if (test-connection $ip.("IPAddress") -count 1 -quiet) {
        write-host $ip.("IPAddress") "Ping succeeded." -foreground green

    } else {
         write-host $ip.("IPAddress") "Ping failed." -foreground red
    }
   
}

Write-Host "Pinging Completed."
Avatar of Jose Colmenares

ASKER

In my .csv I only have the name of computers and the Header is ComputerName.

I don´t have the ip address.
Avatar of Sarang Tinguria
Review below link..Does not have exactly how to use the csv function but you may get workaround
https://www.petri.com/test-network-connectivity-powershell-test-connection-cmdlet
refactored to comply with user response and added to a code block
<#
.SYNOPSIS
  Powershell script to ping all IP addresseses in a CSV file.
.DESCRIPTION
  This PowerShell script reads a CSV file and pings all the IP addresses listed in the IPAddress column.
.PARAMETER <csvfile>
   File name and path of the CSV file to read.
.NOTES
  Version:  
1.0  Alessio Pe
1.01 David Johnson
.EXAMPLE
  Ping-IPList c:\IPaddressList.csv
#>

Param(
  [Parameter(Mandatory=$true, position=0)][string]$csvfile
)
Write-Host "Reading file" $csvfile
$ipaddresses = import-csv $csvfile
Write-Host "Started Pinging.."
foreach( $ip in $ipaddresses) {
$computer = $ip.computername
    if (test-connection -ComputerName $computer -count 1 -quiet) {
        write-host $computer "Ping succeeded." -foreground green
    } else {
         write-host $computer "Ping failed." -foreground red
    }
   }
   Write-Host "Pinging Completed."
 

Open in new window

Thanks u. It works. I need export a .csv with the 5000 results. How Can I do it?
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, had to fix an error in line 62.
If you already tested the script before this comment (and wondered about the strange results), download it again, or change line 62 to this:
	$rsJob = [powershell]::Create().AddScript($sbPing).AddArgument($_)

Open in new window

I can´t execute it

the error is Script descriptions is disabled in this system
In an elevated PS console, enter
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force

Open in new window

This command solved my necessity, Besides checking if my computers are active and turned on I get to know the ip address of each one.