VMware Cloud Community
MMAgeek
Enthusiast
Enthusiast
Jump to solution

having some problems with get-esxcli

Hi, i'm trying to write a script to configure esxi servers that will find the correct vmhba number of the software iscsi adapters then add the vmknics to them to set multipathing up (i.e  esxcli swiscsi nic add -n vmk2 -d vmhba37 but the vmhba number will vary between servers).

Initially i just want to list the nics bound to the adapter of an already configured server for test purposes so i ran

# Find the correct vmhba of the software iscsi adapter

$HBANumber = Get-VMHost $vmhost | Get-VMHostHba | where {$_.Model -like "iSCSI Software Adapter"} | Select Device
# list the nic bound to iscsi adapter
$esxCli = Get-EsxCli –Server $vmhost
$esxCli.swiscsi.nic.list("$HBANumber")

I got the error:

The remote server returned an error: (500) Internal Server Error.

At line:1 char:25

+ $esxCli.swiscsi.nic.list <<<< ($HBANumber)

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : MethodInvocationException

I worked out that my $HBANumber line in my script is returning other text than just vmhbaxx:

[vSphere PowerCLI] C:\Program Files\VMware\Infrastructure\vSphere PowerCLI> Write-Host $HBANumber

@{Device=vmhba39}

How can i fix this so that the first line of my script returns only vmhbaxx and not the @{device= part?

Thanks

Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You just want the value (vmhba39) not the object.

Try changing that line to

$HBANumber = Get-VMHost $vmhost | Get-VMHostHba | where {$_.Model -like "iSCSI Software Adapter"} | %{$_.Device}
The returned value in $HBANumber can be a single value or an array of values (if you have more than 1 iSCSI adapter defned).
If you have an array you should call EsxCli in a loop
$HBANumber | %{
   $esxCli.swiscsi.nic.list("$_")
}
If you want a script that handles a single HBA as well as an array, you could do
$HBANumber = @(Get-VMHost $vmhost | Get-VMHostHba | where {$_.Model -like "iSCSI Software Adapter"} | %{$_.Device})

That way you force, even if it is a single HBA, the line to always return an array.


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

View solution in original post

Reply
0 Kudos
9 Replies
LucD
Leadership
Leadership
Jump to solution

You just want the value (vmhba39) not the object.

Try changing that line to

$HBANumber = Get-VMHost $vmhost | Get-VMHostHba | where {$_.Model -like "iSCSI Software Adapter"} | %{$_.Device}
The returned value in $HBANumber can be a single value or an array of values (if you have more than 1 iSCSI adapter defned).
If you have an array you should call EsxCli in a loop
$HBANumber | %{
   $esxCli.swiscsi.nic.list("$_")
}
If you want a script that handles a single HBA as well as an array, you could do
$HBANumber = @(Get-VMHost $vmhost | Get-VMHostHba | where {$_.Model -like "iSCSI Software Adapter"} | %{$_.Device})

That way you force, even if it is a single HBA, the line to always return an array.


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

Reply
0 Kudos
MMAgeek
Enthusiast
Enthusiast
Jump to solution

Thanks, that worked!

So if i want to add vmk to adapter for multipathing i can just change it to

$HBANumber | %{$esxCli.swiscsi.nic.add("vmk2", "$_")}

right? (ill have a test server next week to start playing with this Smiley Happy )

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, that's correct.


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

MMAgeek
Enthusiast
Enthusiast
Jump to solution

great, thanks for your help!

Reply
0 Kudos
MMAgeek
Enthusiast
Enthusiast
Jump to solution

I have managed to get a test server and noticed some weird behaviour with this.

If i havent yet bound any vmknics to the software iscsi adapter and run the command from SSH

esxcli swiscsi nic list -d vmhba33

it returns a message saying no nics found for this adapter, as it should do.

If i run the command from PowerCLI:

$HBANumber | %{$esxCli.swiscsi.nic.list("$_")} 

or even manually specifying the vmhba:

$esxcli.swiscsi.nic.list("vmhba33")

I get the following error instead of it just saying there are no nics found

[vSphere PowerCLI] C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> $esxcli.swiscsi.nic.list("vmhba33")
The remote server returned an error: (500) Internal Server Error.
At line:1 char:25
+ $esxcli.swiscsi.nic.list <<<< ("vmhba33")
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodInvocationException

Once i add a nic through SSH

esxcli swiscsi nic add -n vmk2 -d vmhba33

and then run the list command through PowerCLI it returns some values correctly:

[vSphere PowerCLI] C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> $esxcli.swiscsi.nic.list("vmhba33")

NICdriver       : e1000

driverversion   : 8.0.3.2-1vmw-NAPI

ethernetspeed   : 1000

firmwareversion : N/A

ipv4address     : 10.10.1.1

ipv4netmask     : 255.255.255.0

ipv6addresses   :

linkconnected   : true

macaddress      : 00:0c:29:49:9e:97

mtu             : 9000

pNicname        : vmnic3

packetsreceived : 9011

packetssent     : 51

portsreserved   : 63488~65536

tcpchecksum     : false

toe             : false

tso             : true

vNicname        : vmk2

vlan            : true

vlanId          : 0

So thats the first odd thing i noticed.

Second part is I can't add any vmk using powerCLI, i get an error even when specifying vmhba33 manually:

[vSphere PowerCLI] C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> $esxcli.swiscsi.nic.add("vmk3", "vmhba33")

The remote server returned an error: (500) Internal Server Error.

At line:1 char:24

+ $esxcli.swiscsi.nic.add <<<< ("vmk3", "vmhba33")

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : MethodInvocationException

What am i doing wrong?

//EDIT//

Got it working changed the vmk and vmhba values around

from  $esxcli.swiscsi.nic.add("vmk3", "vmhba33")

to  $esxcli.swiscsi.nic.add("vmhba33", "vmk3")

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Thanks for the info. Didn't know the order of the parameters on the add command either.

This Get-EsxCli interface is not very well documented yet.

And it looks indeed as if the list command has a bug when the iscsi adapter has no vmknic attached to it.


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

Reply
0 Kudos
yboychev
Hot Shot
Hot Shot
Jump to solution

In terms of Get-EsxCLI documentation and how to work with it there are several things that might be helpfull:

  • For every command in ESXCLI you could retrieve help for the command itself and the parameters it does accept. For your case it would be:

$esxCLI.swiscsi.nic.help("add")

To be honest I'm not sure whether the parameters described in the help follow the sequence as in the actual method signature. If you want to double check the signature of the method you can see it in the Value property when you execute:

$esxCLI.swiscsi.nic.add

Hope this is helpful,

Best regards

Yavor,

PoweCLI team

PS Just a question out of curiosity to Luc:

Why do you do:

Get-VMHostHba | where {$_.Model -like "iSCSI Software Adapter"}

when you can use the Type filter like:

Get-VMHostHba -Type iSCSI

EDIT:

Got the answer of the iSCSI question 🙂

Reply
0 Kudos
nikol
VMware Employee
VMware Employee
Jump to solution

Hi,

it looks like there's indeed a problem with the error message of the "list" method invocation. This is environment-specific issue: on ESX4.0 esxcli does not throw an error when there are no nics on the adapter, while on ESX 4.1 esxcli itself throws an error which Get-EsxCLI wrapper shows as an "Internal Server Error".

Note that you can use the help() method to see the available methods of a namespace and the signatures of the methods. You can call the help() method on an esxcli namespace to view the available objects, or on an esxcli object to view its methods and info about their usage. Here're some examples with the swiscsi namespace:

$esxcli.swiscsi.help()                       # Lists the available objects of swiscsi

$esxcli.swiscsi.nic.help()                  # Lists the available methods you can call on iSCSI NICs

$esxcli.swiscsi.nic.help("add")          # Shows info about the usage of the "add()" method - parameters and expected order of arguments

Regards,

Irina

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Hi Yavor, that's an old habit that I have to get rid off 🙂

You're right, I should specify the Type of the HBA on the Get-VMHostHBA cmdlet.


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

Reply
0 Kudos