Here is my "enterprise ready" ping-in-powershell...take out all the log
statements.
function test-ping ([string]$server)
{
[string]$routine = "test-ping:"
trap
{
# we should only get here if the New-Object
fails.
log $routine "Cannot create
System.Net.NetworkInformation.Ping for $server."
return $false
}
$ping = New-Object System.Net.NetworkInformation.Ping
if ($ping)
{
trap
[System.Management.Automation.MethodInvocationException]
{
log $routine "Invalid hostname
specified (cannot resolve $server)."
return $false
}
for ($i = 0; $i -lt 5; $i++)
{
$rslt = $ping.Send($server)
if ($rslt -and ($rslt.Status
-eq [System.Net.NetworkInformation.IPStatus]::Success))
{
log $routine
"Can ping $server. $routine successful on attempt $i."
$ping = $null
return $true
}
sleep -seconds 1
}
$ping = $null
}
log $routine "Cannot ping $server. $routine failed after 5
attempts."
return $false
}
From: Steven Peck [mailto:[email protected]]
Sent: Wednesday, February 27, 2013 1:50 PM
To: NT System Admin Issues
Subject: Re: Ping by name tool
oh hey
http://www.myitforum.com/forums/m172057-print.aspx
4th reply. Looks to be PowerShell v1 stuff but seems to have what you asked
about.
$Computer = "remotecomputer.domain.com<http://remotecomputer.domain.com>"
if (($Ping = Get-WmiObject -Class Win32_PingStatus -Filter
"Address='$Computer'").StatusCode -eq 0) {
nbtstat -A $Ping.ProtocolAddress
} else { "no response to ping" }
add a $servers = get-content "list.txt" and then put the rest in a for loop.
On Wed, Feb 27, 2013 at 10:39 AM, Steven Peck
<[email protected]<mailto:[email protected]>> wrote:
The BSonPosh module has a ton of stuff similar to this you could use as a
starting point
http://bsonposh.codeplex.com/
Since it's a script module you can open them up and see how they work as well.
On Wed, Feb 27, 2013 at 10:24 AM, David Lum
<[email protected]<mailto:[email protected]>> wrote:
I'm looking for a ping tool that will ping a text file list of hostnames and
return the reply, IP address and the NetBIOS name. Here's what I currently have
to do:
Get list of machine names from AD, McAfee, or other systems. Ping the name
With the returned IP, do an NBTSTAT -A to check the NetBIOS name to see if it
matches the pinged host name
I have to do this because frequently our VPN'd systems don't have a correct DNS
entry, so some management software gets tripped up.
I could do a search for free ping tools, but figured a query here might save me
time if someone has a tool they do that already meets this requirement.
Advanced IP scanner comes close, but only accepts IP's and not host names as
what to ping.
Ideally the output would be in a CSV format. I'm guessing PowerShell can do
this too?
David Lum
Sr. Systems Engineer // NWEATM
Office 503.548.5229<tel:503.548.5229> // Cell (voice/text)
503.267.9764<tel:503.267.9764>
~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~
---
To manage subscriptions click here:
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to
[email protected]<mailto:[email protected]>
with the body: unsubscribe ntsysadmin
~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~
---
To manage subscriptions click here:
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to
[email protected]<mailto:[email protected]>
with the body: unsubscribe ntsysadmin
~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~
---
To manage subscriptions click here:
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to [email protected]
with the body: unsubscribe ntsysadmin