Script to Ping/Resovle names given IP

I have a list of IP's that I need to get the computer names for and status. How can I script this?
Scotch TechITAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Elango SathyadevSenior Systems EngineerCommented:
Here is the script

#Get List of IPs to Check
$InputFile = 'e:\Temp\list.txt'
$IPaddresses = get-content $InputFile
$reader = New-Object IO.StreamReader $InputFile
    while($reader.ReadLine() -ne $null){ $TotalIPs++ }
write-host    ""    
write-Host "Performing Checks on each IP address..."    
        foreach($IP in $IPaddresses) {
            ## Progress bar
            $percentdone = (($i / $TotalIPs) * 100)
            $percentdonerounded = "{0:N0}" -f $percentdone
            Write-Progress -Activity "Performing nslookups" -CurrentOperation "Working on IP: $IP (IP $i of $TotalIPs)" -Status "$percentdonerounded% complete" -PercentComplete $percentdone
            ## End progress bar
            try {
                []::resolve($IP) | Select HostName,AddressList
                catch {
                    Write-host "$IP was not found. $_" -ForegroundColor Green
write-host    ""            
write-Host "Pinging each address..."
        foreach($IP in $IPaddresses) {
            ## Progress bar
            $percentdone2 = (($j / $TotalIPs) * 100)
            $percentdonerounded2 = "{0:N0}" -f $percentdone2
            Write-Progress -Activity "Performing pings" -CurrentOperation "Pinging IP: $IP (IP $j of $TotalIPs)" -Status "$percentdonerounded2% complete" -PercentComplete $percentdone2
            ## End progress bar
                if (test-Connection -ComputerName $IP -Count 2 -Quiet ) {  
                    write-Host "$IP responded" -ForegroundColor Green 
                    } else 
                    { Write-Warning "$IP does not respond to pings"              
write-host    ""        
write-host "Done!"

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chris DentPowerShell DeveloperCommented:
Shorter, but without progress.
function Get-State {
        [Parameter(ValueFromPipeline = $true)]

    process {
        try {
            $HostName = [System.Net.Dns]::GetHostEntry($IPAddress).HostName
        } catch {
            $HostName = ""

            IPAddress      = $IPAddress
            HostName       = $HostName
            RespondsToPing = Test-Connection $IPAddress -Quiet -Count 2

Get-Content TheListOfIPs.txt | Get-State

Open in new window

Scotch TechITAuthor Commented:
Damn, those are some intimidating looking scripts! Thanks, I'll test them both out.
Scotch TechITAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.