Skip to content

Instantly share code, notes, and snippets.

@bldrdash
Created November 3, 2025 16:36
Show Gist options
  • Select an option

  • Save bldrdash/3e1b6bf0960162e9958596d47234ce32 to your computer and use it in GitHub Desktop.

Select an option

Save bldrdash/3e1b6bf0960162e9958596d47234ce32 to your computer and use it in GitHub Desktop.
Ping Subnet in Powershell
# Code was written by Google Search AI (probably Gemini)
function Ping-Subnet ($SubnetPrefix, $StartIP, $EndIP) {
# Define the range of IP addresses to sweep
$IPs = $StartIP..$EndIP | ForEach-Object { "$SubnetPrefix.$_" }
# Perform the ping sweep in parallel
$Results = $IPs | ForEach-Object -Parallel {
$IP = $_
try {
$PingResult = Test-Connection -ComputerName $IP -Count 1 -Quiet -ErrorAction SilentlyContinue
if ($PingResult) {
[PSCustomObject]@{
IPAddress = $IP
Status = "Active"
}
} else {
[PSCustomObject]@{
IPAddress = $IP
Status = "Inactive"
}
}
} catch {
[PSCustomObject]@{
IPAddress = $IP
Status = "Error"
ErrorMessage = $_.Exception.Message
}
}
} -ThrottleLimit 100 # Adjust ThrottleLimit based on your network and system resources
# Output the results
$Results | Format-Table -AutoSize
}
# Example usage: Ping the subnet 192.168.1.0/24 from .1 to .254
Ping-Subnet -SubnetPrefix "192.168.1" -StartIP 1 -EndIP 254
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment