Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Testing for network availability

Closed Thread
 
Thread Tools Display Modes
Old 01-02-2007   #1 (permalink)
Andy Webster
Guest


 

Testing for network availability

I am trying to write some scripts that return BIOS info using WMI.

I would like to check for the availability of a networked PC prior to
running the WMI command. Is there an easy way to do this?

I started by trying to use ping and return the ping time in ms but the
command is very convoluted and still needs work. Surely there must be an
easier way.

The basis of my current command:
(((ping $ComputerIP -n 1 | where {$_.Contains("Reply")} | split-string ":" |
where {$_.Contains("time")} | split-string " ")[2]) | split-string "=")[1] |
split-string "ms"
Old 01-02-2007   #2 (permalink)
$hay
Guest


 

Re: Testing for network availability

try this, TTL is available only if the destination is alive

ping $ComputerIP -n 1 | if ($_.Contains("TTL")) { do something} ....

$hay

"Andy Webster" <AndyWebster@discussions.microsoft.com> wrote in message
news:BD278623-84EA-44E7-A989-B2294F4D5A44@microsoft.com...
>I am trying to write some scripts that return BIOS info using WMI.
>
> I would like to check for the availability of a networked PC prior to
> running the WMI command. Is there an easy way to do this?
>
> I started by trying to use ping and return the ping time in ms but the
> command is very convoluted and still needs work. Surely there must be an
> easier way.
>
> The basis of my current command:
> (((ping $ComputerIP -n 1 | where {$_.Contains("Reply")} | split-string ":"
> |
> where {$_.Contains("time")} | split-string " ")[2]) | split-string "=")[1]
> |
> split-string "ms"



Old 01-02-2007   #3 (permalink)
$hay
Guest


 

Re: Testing for network availability

maybe this can help

http://lantoolbox.com/network-admini...om-powershell/

$hay

"Andy Webster" <AndyWebster@discussions.microsoft.com> wrote in message
news:BD278623-84EA-44E7-A989-B2294F4D5A44@microsoft.com...
>I am trying to write some scripts that return BIOS info using WMI.
>
> I would like to check for the availability of a networked PC prior to
> running the WMI command. Is there an easy way to do this?
>
> I started by trying to use ping and return the ping time in ms but the
> command is very convoluted and still needs work. Surely there must be an
> easier way.
>
> The basis of my current command:
> (((ping $ComputerIP -n 1 | where {$_.Contains("Reply")} | split-string ":"
> |
> where {$_.Contains("time")} | split-string " ")[2]) | split-string "=")[1]
> |
> split-string "ms"



Old 01-02-2007   #4 (permalink)
Andy Webster
Guest


 

Re: Testing for network availability

Thanks for the help $hay

Could not seem to pipe into an If statement so ended up with this to
develope on:

ForEach ( $i in 221..225 )
{
$ComputerIP = "192.168.1." + $i

$PingResponse = ping $ComputerIP -n 1

#--Set $Available to false
$Available = (1 -eq 2)

ForEach ($line in $PingResponse)
{
#--If reply contains TTL set $Available to True
If ($line.Contains("TTL")){$Available = (1 -eq 1)}
}

If($Available)
{
write-host -ForegroundColor GREEN $ComputerIP" - AVAILABLE"
}
Else
{
write-host -ForegroundColor RED $ComputerIP" - UNAVAILABLE"
}
}


"$hay" wrote:

> maybe this can help
>
> http://lantoolbox.com/network-admini...om-powershell/
>
> $hay
>
> "Andy Webster" <AndyWebster@discussions.microsoft.com> wrote in message
> news:BD278623-84EA-44E7-A989-B2294F4D5A44@microsoft.com...
> >I am trying to write some scripts that return BIOS info using WMI.
> >
> > I would like to check for the availability of a networked PC prior to
> > running the WMI command. Is there an easy way to do this?
> >
> > I started by trying to use ping and return the ping time in ms but the
> > command is very convoluted and still needs work. Surely there must be an
> > easier way.
> >
> > The basis of my current command:
> > (((ping $ComputerIP -n 1 | where {$_.Contains("Reply")} | split-string ":"
> > |
> > where {$_.Contains("time")} | split-string " ")[2]) | split-string "=")[1]
> > |
> > split-string "ms"

>
>
>

Old 01-02-2007   #5 (permalink)
Gaurhoth
Guest


 

Re: Testing for network availability

Check out http://sapien.eponym.com/blog/_archi...8/2549814.html which has the following example function:

Function Ping-Name {
PROCESS {
$wmi = get-wmiobject -query "SELECT * FROM Win32_PingStatus WHERE Address = '$_'"
if ($wmi.StatusCode -eq 0) { $_ }
}
}

The wmi call basically tells the local PC to ping the remote address and returns statuscode of 0 if successful. The way this function is setup, you can use it like a cmd-let and PIPE a list of machines to ping and returns ONLY live machines. You can use IP addresses or hostnames.

As an alternate to your foreach method, you can create a list of computers using:

PS ps:\> $computerips = @()
PS ps:\> 221..225 | % { $computerip += "192.168.1.$_" }

Then pipe this to Ping-Name like so:

PS ps:\> $computerips | Ping-Name

--

gaurhoth
http://gaurhothw.spaces.live.com/


"Andy Webster" <AndyWebster@discussions.microsoft.com> wrote in message news:B6EDED6D-8F0B-4A51-9FC4-8B4E7AB15EB4@microsoft.com...
> Thanks for the help $hay
>
> Could not seem to pipe into an If statement so ended up with this to
> develope on:
>
> ForEach ( $i in 221..225 )
> {
> $ComputerIP = "192.168.1." + $i
>
> $PingResponse = ping $ComputerIP -n 1
>
> #--Set $Available to false
> $Available = (1 -eq 2)
>
> ForEach ($line in $PingResponse)
> {
> #--If reply contains TTL set $Available to True
> If ($line.Contains("TTL")){$Available = (1 -eq 1)}
> }
>
> If($Available)
> {
> write-host -ForegroundColor GREEN $ComputerIP" - AVAILABLE"
> }
> Else
> {
> write-host -ForegroundColor RED $ComputerIP" - UNAVAILABLE"
> }
> }
>
>
> "$hay" wrote:
>
>> maybe this can help
>>
>> http://lantoolbox.com/network-admini...om-powershell/
>>
>> $hay
>>
>> "Andy Webster" <AndyWebster@discussions.microsoft.com> wrote in message
>> news:BD278623-84EA-44E7-A989-B2294F4D5A44@microsoft.com...
>> >I am trying to write some scripts that return BIOS info using WMI.
>> >
>> > I would like to check for the availability of a networked PC prior to
>> > running the WMI command. Is there an easy way to do this?
>> >
>> > I started by trying to use ping and return the ping time in ms but the
>> > command is very convoluted and still needs work. Surely there must be an
>> > easier way.
>> >
>> > The basis of my current command:
>> > (((ping $ComputerIP -n 1 | where {$_.Contains("Reply")} | split-string ":"
>> > |
>> > where {$_.Contains("time")} | split-string " ")[2]) | split-string "=")[1]
>> > |
>> > split-string "ms"

>>
>>
>>

Old 01-02-2007   #6 (permalink)
Andy Webster
Guest


 

Re: Testing for network availability

Thanks again, now got:

ForEach ( $i in 221..225 )
{
$ComputerIP = "192.168.1." + $i

If(((gwmi Win32_PingStatus -Filter "Address='$ComputerIP'").StatusCode) -eq
0)
{
write-host -ForegroundColor GREEN $ComputerIP" - AVAILABLE"
}
Else
{
write-host -ForegroundColor RED $ComputerIP" - UNAVAILABLE"
}
}


"Gaurhoth" wrote:

> Check out http://sapien.eponym.com/blog/_archi...8/2549814.html which has the following example function:
>
> Function Ping-Name {
> PROCESS {
> $wmi = get-wmiobject -query "SELECT * FROM Win32_PingStatus WHERE Address = '$_'"
> if ($wmi.StatusCode -eq 0) { $_ }
> }
> }
>
> The wmi call basically tells the local PC to ping the remote address and returns statuscode of 0 if successful. The way this function is setup, you can use it like a cmd-let and PIPE a list of machines to ping and returns ONLY live machines. You can use IP addresses or hostnames.
>
> As an alternate to your foreach method, you can create a list of computers using:
>
> PS ps:\> $computerips = @()
> PS ps:\> 221..225 | % { $computerip += "192.168.1.$_" }
>
> Then pipe this to Ping-Name like so:
>
> PS ps:\> $computerips | Ping-Name
>
> --
>
> gaurhoth
> http://gaurhothw.spaces.live.com/
>
>
> "Andy Webster" <AndyWebster@discussions.microsoft.com> wrote in message news:B6EDED6D-8F0B-4A51-9FC4-8B4E7AB15EB4@microsoft.com...
> > Thanks for the help $hay
> >
> > Could not seem to pipe into an If statement so ended up with this to
> > develope on:
> >
> > ForEach ( $i in 221..225 )
> > {
> > $ComputerIP = "192.168.1." + $i
> >
> > $PingResponse = ping $ComputerIP -n 1
> >
> > #--Set $Available to false
> > $Available = (1 -eq 2)
> >
> > ForEach ($line in $PingResponse)
> > {
> > #--If reply contains TTL set $Available to True
> > If ($line.Contains("TTL")){$Available = (1 -eq 1)}
> > }
> >
> > If($Available)
> > {
> > write-host -ForegroundColor GREEN $ComputerIP" - AVAILABLE"
> > }
> > Else
> > {
> > write-host -ForegroundColor RED $ComputerIP" - UNAVAILABLE"
> > }
> > }
> >
> >
> > "$hay" wrote:
> >
> >> maybe this can help
> >>
> >> http://lantoolbox.com/network-admini...om-powershell/
> >>
> >> $hay
> >>
> >> "Andy Webster" <AndyWebster@discussions.microsoft.com> wrote in message
> >> news:BD278623-84EA-44E7-A989-B2294F4D5A44@microsoft.com...
> >> >I am trying to write some scripts that return BIOS info using WMI.
> >> >
> >> > I would like to check for the availability of a networked PC prior to
> >> > running the WMI command. Is there an easy way to do this?
> >> >
> >> > I started by trying to use ping and return the ping time in ms but the
> >> > command is very convoluted and still needs work. Surely there must be an
> >> > easier way.
> >> >
> >> > The basis of my current command:
> >> > (((ping $ComputerIP -n 1 | where {$_.Contains("Reply")} | split-string ":"
> >> > |
> >> > where {$_.Contains("time")} | split-string " ")[2]) | split-string "=")[1]
> >> > |
> >> > split-string "ms"
> >>
> >>
> >>

Old 01-02-2007   #7 (permalink)
Rob Campbell
Guest


 

RE: Testing for network availability

Something that might be easier to work with

ping $i
if ($(arp -a $i) -ne "No ARP Entries Found"){

"Andy Webster" wrote:

> I am trying to write some scripts that return BIOS info using WMI.
>
> I would like to check for the availability of a networked PC prior to
> running the WMI command. Is there an easy way to do this?
>
> I started by trying to use ping and return the ping time in ms but the
> command is very convoluted and still needs work. Surely there must be an
> easier way.
>
> The basis of my current command:
> (((ping $ComputerIP -n 1 | where {$_.Contains("Reply")} | split-string ":" |
> where {$_.Contains("time")} | split-string " ")[2]) | split-string "=")[1] |
> split-string "ms"

Old 01-02-2007   #8 (permalink)
Andy Webster
Guest


 

Re: Testing for network availability

Finally, a list of available IPs and their BIOS versions, thanks for all the
help:

ForEach ( $i in 221..225 )
{
$ComputerIP = "10.178.225." + $i

If(((gwmi Win32_PingStatus -Filter "Address='$ComputerIP'").StatusCode) -eq
0)
{
write-host -ForegroundColor GREEN $ComputerIP - (Get-WmiObject WIN32_BIOS
-ComputerName $ComputerIP).SMBIOSBIOSVersion
}
Else
{
write-host -ForegroundColor RED $ComputerIP" - UNAVAILABLE"
}
}


"Gaurhoth" wrote:

> Check out http://sapien.eponym.com/blog/_archi...8/2549814.html which has the following example function:
>
> Function Ping-Name {
> PROCESS {
> $wmi = get-wmiobject -query "SELECT * FROM Win32_PingStatus WHERE Address = '$_'"
> if ($wmi.StatusCode -eq 0) { $_ }
> }
> }
>
> The wmi call basically tells the local PC to ping the remote address and returns statuscode of 0 if successful. The way this function is setup, you can use it like a cmd-let and PIPE a list of machines to ping and returns ONLY live machines. You can use IP addresses or hostnames.
>
> As an alternate to your foreach method, you can create a list of computers using:
>
> PS ps:\> $computerips = @()
> PS ps:\> 221..225 | % { $computerip += "192.168.1.$_" }
>
> Then pipe this to Ping-Name like so:
>
> PS ps:\> $computerips | Ping-Name
>
> --
>
> gaurhoth
> http://gaurhothw.spaces.live.com/
>
>
> "Andy Webster" <AndyWebster@discussions.microsoft.com> wrote in message news:B6EDED6D-8F0B-4A51-9FC4-8B4E7AB15EB4@microsoft.com...
> > Thanks for the help $hay
> >
> > Could not seem to pipe into an If statement so ended up with this to
> > develope on:
> >
> > ForEach ( $i in 221..225 )
> > {
> > $ComputerIP = "192.168.1." + $i
> >
> > $PingResponse = ping $ComputerIP -n 1
> >
> > #--Set $Available to false
> > $Available = (1 -eq 2)
> >
> > ForEach ($line in $PingResponse)
> > {
> > #--If reply contains TTL set $Available to True
> > If ($line.Contains("TTL")){$Available = (1 -eq 1)}
> > }
> >
> > If($Available)
> > {
> > write-host -ForegroundColor GREEN $ComputerIP" - AVAILABLE"
> > }
> > Else
> > {
> > write-host -ForegroundColor RED $ComputerIP" - UNAVAILABLE"
> > }
> > }
> >
> >
> > "$hay" wrote:
> >
> >> maybe this can help
> >>
> >> http://lantoolbox.com/network-admini...om-powershell/
> >>
> >> $hay
> >>
> >> "Andy Webster" <AndyWebster@discussions.microsoft.com> wrote in message
> >> news:BD278623-84EA-44E7-A989-B2294F4D5A44@microsoft.com...
> >> >I am trying to write some scripts that return BIOS info using WMI.
> >> >
> >> > I would like to check for the availability of a networked PC prior to
> >> > running the WMI command. Is there an easy way to do this?
> >> >
> >> > I started by trying to use ping and return the ping time in ms but the
> >> > command is very convoluted and still needs work. Surely there must be an
> >> > easier way.
> >> >
> >> > The basis of my current command:
> >> > (((ping $ComputerIP -n 1 | where {$_.Contains("Reply")} | split-string ":"
> >> > |
> >> > where {$_.Contains("time")} | split-string " ")[2]) | split-string "=")[1]
> >> > |
> >> > split-string "ms"
> >>
> >>
> >>

Old 01-02-2007   #9 (permalink)
Rob Campbell
Guest


 

RE: Testing for network availability

Nevermind. I just realized the problem with that approach. Works good on
the local network, but falls down once you cross a router.

"Rob Campbell" wrote:

> Something that might be easier to work with
>
> ping $i
> if ($(arp -a $i) -ne "No ARP Entries Found"){
>
> "Andy Webster" wrote:
>
> > I am trying to write some scripts that return BIOS info using WMI.
> >
> > I would like to check for the availability of a networked PC prior to
> > running the WMI command. Is there an easy way to do this?
> >
> > I started by trying to use ping and return the ping time in ms but the
> > command is very convoluted and still needs work. Surely there must be an
> > easier way.
> >
> > The basis of my current command:
> > (((ping $ComputerIP -n 1 | where {$_.Contains("Reply")} | split-string ":" |
> > where {$_.Contains("time")} | split-string " ")[2]) | split-string "=")[1] |
> > split-string "ms"

Old 01-02-2007   #10 (permalink)
Rob Campbell
Guest


 

Re: Testing for network availability

FWIW -

if ([bool]$Pingresponse -like "*TTL*")



"Andy Webster" wrote:

> Thanks for the help $hay
>
> Could not seem to pipe into an If statement so ended up with this to
> develope on:
>
> ForEach ( $i in 221..225 )
> {
> $ComputerIP = "192.168.1." + $i
>
> $PingResponse = ping $ComputerIP -n 1
>
> #--Set $Available to false
> $Available = (1 -eq 2)
>
> ForEach ($line in $PingResponse)
> {
> #--If reply contains TTL set $Available to True
> If ($line.Contains("TTL")){$Available = (1 -eq 1)}
> }
>
> If($Available)
> {
> write-host -ForegroundColor GREEN $ComputerIP" - AVAILABLE"
> }
> Else
> {
> write-host -ForegroundColor RED $ComputerIP" - UNAVAILABLE"
> }
> }
>
>
> "$hay" wrote:
>
> > maybe this can help
> >
> > http://lantoolbox.com/network-admini...om-powershell/
> >
> > $hay
> >
> > "Andy Webster" <AndyWebster@discussions.microsoft.com> wrote in message
> > news:BD278623-84EA-44E7-A989-B2294F4D5A44@microsoft.com...
> > >I am trying to write some scripts that return BIOS info using WMI.
> > >
> > > I would like to check for the availability of a networked PC prior to
> > > running the WMI command. Is there an easy way to do this?
> > >
> > > I started by trying to use ping and return the ping time in ms but the
> > > command is very convoluted and still needs work. Surely there must be an
> > > easier way.
> > >
> > > The basis of my current command:
> > > (((ping $ComputerIP -n 1 | where {$_.Contains("Reply")} | split-string ":"
> > > |
> > > where {$_.Contains("time")} | split-string " ")[2]) | split-string "=")[1]
> > > |
> > > split-string "ms"

> >
> >
> >

Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vista SP1 availability Nick Le Lievre Vista General 7 05-02-2008 12:09 PM
Vista sp1 availability Matthew Vista General 8 05-02-2008 08:59 AM
Re: Vista sp1 availability housetrained Vista General 1 03-23-2008 07:05 AM
RC2 Availability David Sanders Vista General 3 10-06-2006 03:38 PM
Clarification on RC1 Availability Andre Da Costa [ActiveWin] Vista General 2 09-06-2006 11:29 PM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50