Created
November 3, 2025 16:36
-
-
Save bldrdash/3e1b6bf0960162e9958596d47234ce32 to your computer and use it in GitHub Desktop.
Ping Subnet in Powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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