I have a range of IP addresses that I’m currently getting their status. I would like to output the results to the Powershell window and to a CSV. Ideally the CSV would have two columns. One for the IP address and the other for its status which is setup for “is active” and “is not active”.
Any ideas on what I would need to add to the below code to achieve this?
Thank you
$ipRange = 1..510
$subnet = “192.168.2.”
foreach ($i in $ipRange) {
$ip = $subnet + $i
if (Test-Connection -ComputerName $ip -Count 1 -Quiet) {
Write-Host “$ip is active”
} else {
Write-Host “$ip is inactive”
}
}
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.