We help IT Professionals succeed at work.

Script to Ping/Resovle names given IP

Scotch Tech
Scotch Tech asked
on
111 Views
Last Modified: 2017-04-18
I have a list of IP's that I need to get the computer names for and status. How can I script this?
Comment
Watch Question

Senior Systems Engineer
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Chris DentPowerShell Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
Shorter, but without progress.
function Get-State {
    [CmdletBinding()]
    param(
        [Parameter(ValueFromPipeline = $true)]
        [String]$IPAddress
    )

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

        [PSCustomObject]@{
            IPAddress      = $IPAddress
            HostName       = $HostName
            RespondsToPing = Test-Connection $IPAddress -Quiet -Count 2
        }
    }
}

Get-Content TheListOfIPs.txt | Get-State

Open in new window

Author

Commented:
Damn, those are some intimidating looking scripts! Thanks, I'll test them both out.

Author

Commented:
thanks