The following script will ping your network and write the status of each IP address to a csv file.
Scanning the IP addresses from 1 to 254
$range = 1..254
On the address range 192.168.1.0/24
$address = “192.168.1.$_”
I used the Test-Connection cmdlet to ping the IP addresses. Here I’m sending 2 pings.
Ping = Test-Connection $address -Quiet -Count 2
I’m sending the result to a csv file using Out-File cmdlet.
Out-File D:\Tech\IpscanResult.csv
I also added a progress bar using Write-Progress cmdlet (Thanks to Bill Stewart)
Write-Progress “Scanning Network” $address -PercentComplete (($_/$range.Count)*100)
Here is the full script:
$range = 1..254
$range | ForEach-Object {
$address = “192.168.1.$_”
Write-Progress “Scanning Network” $address -PercentComplete (($_/$range.Count)*100)
New-Object PSObject -Property @{
Address = $address
Ping = Test-Connection $address -Quiet -Count 2
}
} | Out-File D:\Tech\IpscanResult.csv
Script running:
CSV result:
Enjoy 😉
Very good script indeed.
I see that the results will show True or False for every address – is it possible to show only the True results?
Kind like when running >
1..254 | ForEach-Object {Test-Connection -ComputerName “10.1.1.$_” -Count 1 -ErrorAction SilentlyContinue}
Thanks, M