Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Exception calling "Send" with "1" argument(s) error using PING

Reply
 
Old 07-03-2008   #1 (permalink)
bass_player


 
 

Exception calling "Send" with "1" argument(s) error using PING

I have a PowerShell script which uses the System.Net.NetworkInformation.Ping
object. It reads thru a text file of hostnames and does a PING test. What
I'm curious about is that I get this error every now and then, meaning no
error on first three hostnames from the list, error on the next, etc.

Exception calling "Send" with "1" argument(s): "An exception occurred during
a Ping request."
At line 5, position 22
$Reply = $ping.send($strComputer)

A forum post from the MSDN forum says its by design.
https://forums.microsoft.com/MSDN/Sh...=8895&SiteID=1

Am I missing something?


My System SpecsSystem Spec
Old 07-04-2008   #2 (permalink)


Vista Ultimate 32bit
 
 

Re: Exception calling "Send" with "1" argument(s) error using PING

It made sense to me and I'm not even a .NET developer. Couldn't you simply use an error trap and if you get that error, then know you can't ping that computer for some reason.

A ping alternative is to use the win32_pingstatusclass:

PS C:\> get-wmiobject -query "Select * from win32_pingstatus where address='godot'"


__GENUS : 2
__CLASS : Win32_PingStatus
__SUPERCLASS :
__DYNASTY : Win32_PingStatus
__RELPATH : Win32_PingStatus.Address="godot",BufferSize=32,NoFrag
olveAddressNames=FALSE,SourceRoute="",SourceRouteType
TimeToLive=128,TypeofService=0
__PROPERTY_COUNT : 24
__DERIVATION : {}
__SERVER : PUCK
__NAMESPACE : root\cimv2
__PATH : \\PUCK\root\cimv2:Win32_PingStatus.Address="godot",Bu
,RecordRoute=0,ResolveAddressNames=FALSE,SourceRoute=
,TimestampRoute=0,TimeToLive=128,TypeofService=0
Address : godot
BufferSize : 32
NoFragmentation : False
PrimaryAddressResolutionStatus : 0
ProtocolAddress : 172.16.10.101
ProtocolAddressResolved :
RecordRoute : 0
ReplyInconsistency : False
ReplySize : 32
ResolveAddressNames : False
ResponseTime : 1
ResponseTimeToLive : 128
RouteRecord :
RouteRecordResolved :
SourceRoute :
SourceRouteType : 0
StatusCode : 0
Timeout : 4000
TimeStampRecord :
TimeStampRecordAddress :
TimeStampRecordAddressResolved :
TimestampRoute : 0
TimeToLive : 128
TypeofService : 0
My System SpecsSystem Spec
Old 07-04-2008   #3 (permalink)
bass_player


 
 

Re: Exception calling "Send" with "1" argument(s) error using PING

Thanks for the inputs. I'm trying to monitor computers and servers, check
if they're running before I run a script. I'm trying to convert all of my
VBScripts to PowerShell :-)

"sapienscripter" <guest@xxxxxx-email.com> wrote in message
news:262c35e123e2972b98259f9e65b304a5@xxxxxx-gateway.com...
Quote:

>
> It made sense to me and I'm not even a .NET developer. Couldn't you
> simply use an error trap and if you get that error, then know you can't
> ping that computer for some reason.
>
> A ping alternative is to use the win32_pingstatusclass:
>
> PS C:\> get-wmiobject -query "Select * from win32_pingstatus where
> address='godot'"
>
>
> __GENUS : 2
> __CLASS : Win32_PingStatus
> __SUPERCLASS :
> __DYNASTY : Win32_PingStatus
> __RELPATH :
> Win32_PingStatus.Address="godot",BufferSize=32,NoFrag
>
> olveAddressNames=FALSE,SourceRoute="",SourceRouteType
> TimeToLive=128,TypeofService=0
> __PROPERTY_COUNT : 24
> __DERIVATION : {}
> __SERVER : PUCK
> __NAMESPACE : root\cimv2
> __PATH :
> \\PUCK\root\cimv2:Win32_PingStatus.Address="godot",Bu
>
> ,RecordRoute=0,ResolveAddressNames=FALSE,SourceRoute=
>
> ,TimestampRoute=0,TimeToLive=128,TypeofService=0
> Address : godot
> BufferSize : 32
> NoFragmentation : False
> PrimaryAddressResolutionStatus : 0
> ProtocolAddress : 172.16.10.101
> ProtocolAddressResolved :
> RecordRoute : 0
> ReplyInconsistency : False
> ReplySize : 32
> ResolveAddressNames : False
> ResponseTime : 1
> ResponseTimeToLive : 128
> RouteRecord :
> RouteRecordResolved :
> SourceRoute :
> SourceRouteType : 0
> StatusCode : 0
> Timeout : 4000
> TimeStampRecord :
> TimeStampRecordAddress :
> TimeStampRecordAddressResolved :
> TimestampRoute : 0
> TimeToLive : 128
> TypeofService : 0
>
>
> --
> sapienscripter
>
> Coming Soon: -'Managing Active Directory with Windows PowerShell: TFM'
> (http://www.sapienpress.com/ad.asp)-
>
> '[image: http://www.scriptinganswers.com/_images/logo_mvp.gif]'
> (http://www.scriptinganswers.com/_images/logo_mvp.gif)
>
> 'My Blog' (http://blog.sapien.com/)
> 'FollowMe on Twitter' (http://www.twitter.com/JeffHicks)
My System SpecsSystem Spec
Old 07-04-2008   #4 (permalink)


Vista Ultimate 32bit
 
 

Re: Exception calling "Send" with "1" argument(s) error using PING

Here's a function that might help.

Code:
Function Ping-Host {
  PROCESS {
$errorActionPreference="SilentlyContinue"

 $wmi = get-wmiobject -query “SELECT * FROM Win32_PingStatus WHERE Address = '$_'"
 if ($wmi.StatusCode -eq 0) {
  $_
 }
  }
}
This is designed to take pipeline input.

"localhost" | ping-host
or
get-content servers.txt | ping-host

If the computer can be pinged, the name is written to the pipeline. Moving from VBScript to PowerShell requires a paradigm shift as much as anything.
My System SpecsSystem Spec
Old 07-08-2008   #5 (permalink)
kuma


 
 

Re: Exception calling "Send" with "1" argument(s) error using PING

If you're computers are setup to not respond to ICMP echoes you can try this,
I can't remember where I found it at the moment.

function Test-Port
{
param([string]$srv,$port=135,$timeout=750,[switch]$verbose=$false)
$ErrorActionPreference = "SilentlyContinue"
$tcpclient = new-Object System.Net.Sockets.TcpClient
$iar = $tcpclient.BeginConnect($srv,$port,$null,$null)
$wait = $iar.AsyncWaitHandle.WaitOne($timeout,$false)
if(!$wait)
{
$tcpclient.Close()
if($verbose){Write-Host "Connection Timeout"}
Return $false
}
else
{
$error.Clear()
$tcpclient.EndConnect($iar) | out-Null
if($error[0]){if($verbose){write-host $error[0]};$failed = $true}
$tcpclient.Close()
}
if($failed){return $false}else{return $true}
}

This will allow you to specify a specific port on a specific machine. I use
it to see if the ports for telnet, ssh, etc.. are open so i can close them.
But you could use it instead of a ping.
--
It says "Press Any Key To Continue..." but I can''''t find the "Any" key......


"sapienscripter" wrote:
Quote:

>
> Here's a function that might help.
>
>
> Code:
> --------------------
> Function Ping-Host {
> PROCESS {
> $errorActionPreference="SilentlyContinue"
>
> $wmi = get-wmiobject -query “SELECT * FROM Win32_PingStatus WHERE Address = '$_'"
> if ($wmi.StatusCode -eq 0) {
> $_
> }
> }
> }
> --------------------
>
>
> This is designed to take pipeline input.
>
> "localhost" | ping-host
> or
> get-content servers.txt | ping-host
>
> If the computer can be pinged, the name is written to the pipeline.
> Moving from VBScript to PowerShell requires a paradigm shift as much as
> anything.
>
>
> --
> sapienscripter
>
> Coming Soon: -'Managing Active Directory with Windows PowerShell: TFM'
> (http://www.sapienpress.com/ad.asp)-
>
> '[image: http://www.scriptinganswers.com/_images/logo_mvp.gif]'
> (http://www.scriptinganswers.com/_images/logo_mvp.gif)
>
> 'My Blog' (http://blog.sapien.com/)
> 'FollowMe on Twitter' (http://www.twitter.com/JeffHicks)
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Exception calling "CreateInstance" with "2" argument(s): for Microsoft.Update.UpdateColl PowerShell
Unwanted Multiple contacts in "To","CC","BCC" of email send catago Vista mail
Vista not wotking with "My Computer" or "Control Panel", "Screen Saver" Vista General
WM5 Sync with Vista "Windows Calender", "Contacts", and "Mail" Vista General
interesting "issue" or "bug" with psobjects when calling DOTNET framework stuff PowerShell


Vista Forums 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 Ltd

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