header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Network status script help
Last Post 17 Oct 2007 08:07 PM by brandanf. 2 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
brandanfUser is Offline
New Member
New Member
Posts:7

--
17 Oct 2007 02:57 PM  
I have only been working with powershell for about a week so i was wondering if my logic was completely off here or if i am just going about this all wrong.
I am playing with this script that will return the localhosts ipaddress, default gateway and then ping by ip and name. The problem i am having is with the PrimaryAddressResolutionStatus (which should return 0 if the ip is pingable)

OK, so to get the ping result i use this:
$iptest=Get-WmiObject -Class Win32_PingStatus -Filter "Address='4.2.2.2'" |Select-Object -property PrimaryAddressResolutionStatus

now when i run this in powershell i get a result of 0 as expected, but if i view what is being stored in the ariable $iptest: it returns nothing.

Why is $iptest empty?



When i run the next line it always "fails" because of this.

if ($iptest -eq 0) {Write-Output "Sucess"} elseif ($iptest -ne "0") {Write-Output "Fail"}


Thanks in advance for any info on this.

bsonposhUser is Offline
Basic Member
Basic Member
Posts:388

--
17 Oct 2007 03:16 PM  
I would suggest using StatusCode instead, but what happens if you do
$iptest = (Get-WmiObject -Class Win32_PingStatus -Filter "Address='4.2.2.2'").PrimaryAddressResolutionStatus

I would also avoid this logic
if ($iptest -eq 0) {Write-Output "Sucess"} elseif ($iptest -ne "0") {Write-Output "Fail"}

Maybe something like
if($iptest -ne 0){Write-Output "Fail"}
brandanfUser is Offline
New Member
New Member
Posts:7

--
17 Oct 2007 08:07 PM  
Thanks for the quick reply, i was hoping that it wasnt something so simple.. I seem to be making this harder than it really is.

Thanks for taking the time to help. :)


You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer