Get IP Addresses from a List of Machines

I need to get IP addresses from a list of machines, so I googled it…needs to use test-connection command, and here is the full script:

# Get IP Addresses from a List of Machine Name

# 07052015

$pcs = Get-Content “c:\test\pc.txt”

foreach ($pc in $pcs)

{

#If computer is online,return true , using quiet switch, count means only once eacho request to send

if (Test-Connection $pc -Count 1 -Quiet)

{

Test-Connection $pc -Count 1 -ErrorAction Stop | Select Address, IPV4Address | Out-file -append “c:\test\result.txt”

}

else

{

“$pc is offline” | Out-File -Append “c:\test\result.txt”

}

}

Leave a Reply