VMware Cloud Community
troyemc
Contributor
Contributor
Jump to solution

ESX ping with powercli

Hi Experts,

I run this code and it didn't return any error:

$esxcli2 = Get-ESXCLI -VMHost host01.lab.com -V2

$arguments = $esxcli2.network.diag.ping.CreateArgs()

$arguments.host = "10.10.10.10"

$arguments.count = 3

$esxcli2.network.diag.ping.Invoke($arguments)

How do I verify the result?

Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
mattboren
Expert
Expert
Jump to solution

Hello, troyemc-

If you grab the result of having invoked that method, you can check the Summary property of the return to see info about the ping requests.  Like:

$oReturn = $esxcli2.network.diag.ping.Invoke($arguments)

$oReturn.Summary

Duplicated     : 0

HostAddr       : 10.10.10.10

PacketLost     : 0

Recieved       : 3

RoundtripAvg   : 334

RoundtripAvgMS : 0

RoundtripMax   : 393

RoundtripMaxMS : 0

RoundtripMin   : 298

RoundtripMinMS : 0

Transmitted    : 3

So, you could check whatever things are important to you -- that none were lost, that the latency was acceptable, etc.  That help?

View solution in original post

Reply
0 Kudos
5 Replies
mattboren
Expert
Expert
Jump to solution

Hello, troyemc-

If you grab the result of having invoked that method, you can check the Summary property of the return to see info about the ping requests.  Like:

$oReturn = $esxcli2.network.diag.ping.Invoke($arguments)

$oReturn.Summary

Duplicated     : 0

HostAddr       : 10.10.10.10

PacketLost     : 0

Recieved       : 3

RoundtripAvg   : 334

RoundtripAvgMS : 0

RoundtripMax   : 393

RoundtripMaxMS : 0

RoundtripMin   : 298

RoundtripMinMS : 0

Transmitted    : 3

So, you could check whatever things are important to you -- that none were lost, that the latency was acceptable, etc.  That help?

Reply
0 Kudos
troyemc
Contributor
Contributor
Jump to solution

Reply
0 Kudos
oscarjrodriguez
Contributor
Contributor
Jump to solution

I was hoping to get some help on this one too. I entered the exact same code as did the original poster, but I get the following error.

$esxcli2 = Get-EsxCli -VMHost (Get-VMHost | select -First 1) -V2

$arguments = $esxcli2.network.diag.ping.CreateArgs()

$arguments.Count = 2

$arguments.host = "x.x.x.x"

$esxcli2.network.diag.ping.Invoke($arguments)

Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

At C:\Users\\Documents\practice.ps1:5 char:1

+ $esxcli2.network.diag.ping.Invoke($arguments)

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : OperationStopped: (:) [], FormatException

    + FullyQualifiedErrorId : System.FormatException

Thank you for your time.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Bad choice of variable name ($arguments).

Use another name, then it should work

$esxcli2 = Get-EsxCli -VMHost (Get-VMHost | select -First 1) -V2

$pingArg = $esxcli2.network.diag.ping.CreateArgs()

$pingArg.count = 2

$pingArg.host = "192.168.10.2"

$esxcli2.network.diag.ping.Invoke($pingArg)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
oscarjrodriguez
Contributor
Contributor
Jump to solution

Thank you for your help.

two things helped.

1. changing "Count" to "count" I guess it is case sensitive.

2. Then adding the "$oReturn". I was only getting VMware gibberish before I added the "| Format-List".

$esxcli2 = Get-EsxCli -VMHost (Get-VMHost | select -First 1) -V2

$arguments = $esxcli2.network.diag.ping.CreateArgs()

$arguments.count = 2

$arguments.host = "x.x.x.x"

$esxcli2.network.diag.ping.Invoke($arguments)

$oReturn = $esxcli2.network.diag.ping.Invoke($arguments)

$oReturn.Summary | Format-List

Reply
0 Kudos