VMware Cloud Community
TryllZ
Expert
Expert
Jump to solution

iSCSI Network Port Binding with PowerCLI..

Hi,

I'm trying to bind the PortGroup to the Software iSCSI Adadpter, with the following code.

$esxcli = get-esxcli -v2 -vmhost (get-cluster "iSCSI_Cluster" | get-vmhost)

$esxcli.iscsi.networkportal.add('vmhba65',$true,'vmk3')

$esxcli.iscsi.networkportal.add('vmhba65',$true,'vmk4')

Which when run gives the following error.

PS C:\Users\Administrator> $esxcli = get-esxcli -v2 -vmhost (get-cluster "iSCSI_Cluster" | get-vmhost)

PS C:\Users\Administrator> $esxcli.iscsi.networkportal.add('vmhba65',$true,'vmk3')

Cannot find an overload for "add" and the argument count: "3".

At line:1 char:1

+ $esxcli.iscsi.networkportal.add('vmhba65',$true,'vmk3')

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

    + CategoryInfo          : NotSpecified: (:) [], MethodException

    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

PS C:\Users\Administrator> $esxcli.iscsi.networkportal.add('vmhba65',$true,'vmk4')

Cannot find an overload for "add" and the argument count: "3".

At line:1 char:1

+ $esxcli.iscsi.networkportal.add('vmhba65',$true,'vmk4')

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

    + CategoryInfo          : NotSpecified: (:) [], MethodException

    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

Then I came across the following method from the book Learning PowerCLI : Second Edition.

$VMHost = Get-Cluster "iSCSI_Cluster" | Get-VMHost

$VMHostHba = $VMHost | Get-VMHostHba -Type iSCSI

$VMHostHba | New-IScsiHbaTarget -Type Send -Address 192.168.4.10

$VMHost | Get-VMHostStorage -RescanAllHba

$NetworkAdapter = Get-VMHostNetworkAdapter -VirtualSwitch iSCSISwitch -PortGroup "iSCSI1"

$IscsiManager = Get-View -Id $vmhost.ExtensionData.Configmanager.IscsiManager

$IscsiManager.BindVnic($VMHostHba.Device, $NetworkAdapter.Name)

Which when run gives the following error:

PS C:\Users\Administrator> $VMHost = Get-Cluster "iSCSI_Cluster" | Get-VMHost

PS C:\Users\Administrator> $VMHostHba = $VMHost | Get-VMHostHba -Type iSCSI

PS C:\Users\Administrator> $VMHostHba | New-IScsiHbaTarget -Type Send -Address 192.168.4.10

Address              Port  Type

-------              ----  ----

192.168.4.10         3260  Send

192.168.4.10         3260  Send

PS C:\Users\Administrator> $VMHost | Get-VMHostStorage -RescanAllHba

SoftwareIScsiEnabled

--------------------

True

True

PS C:\Users\Administrator> $NetworkAdapter = Get-VMHostNetworkAdapter -VirtualSwitch iSCSISwitch -PortGroup "iSCSI1"

PS C:\Users\Administrator> $IscsiManager = Get-View -Id $vmhost.ExtensionData.Configmanager.IscsiManager

PS C:\Users\Administrator> $IscsiManager.BindVnic($VMHostHba.Device, $NetworkAdapter.Name)

Exception calling "BindVnic" with "2" argument(s): "There is an error in the XML document."

At line:1 char:1

+ $IscsiManager.BindVnic($VMHostHba.Device, $NetworkAdapter.Name)

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

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : InvalidOperationException

Any thoughts, on how to solve this issue.

Thank You

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I assume that your cluster has more than 1 ESXi node?

In that case, and provided you want to do that action on each node in the cluster, you should do

Get-Cluster "iSCSI_Cluster" | Get-VMHost |

ForEach-Object -Process {

    $esxcli = Get-EsxCli -V2 -VMHost $_

    $bind = @{

        adapter = 'vmhba65'

        force = $true

        nic = 'vmk3'

    }

    $esxcli.iscsi.networkportal.add.Invoke($bind)

}

In your case, the $esxcli variable will be an array, and that is why those calls don't work.


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

View solution in original post

Reply
0 Kudos
11 Replies
LucD
Leadership
Leadership
Jump to solution

When you are using the V2 switch on the Get-EsxCli cmdlet, the way to call the methods changes.
See also PowerCLI 6.3 R1: Get-ESXCLI Why the V2?

Can you try like this?

$bind = @{

  adapter = 'vmhba65'

  force = $true

  nic = 'vmk3'

}

$esxcli.iscsi.networkportal.add.Invoke($bind)


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

Reply
0 Kudos
TryllZ
Expert
Expert
Jump to solution

Hi LucD,

I'm afraid that resulted in another error as below.

PS C:\Users\Administrator> $esxcli = get-esxcli -v2 -vmhost (get-cluster "iSCSI_Cluster" | get-vmhost)

PS C:\Users\Administrator> $bind = @{

>>   adapter = 'vmhba65'

>>   force = $true

>>   nic = 'vmk3'

>> }

PS C:\Users\Administrator> $esxcli.iscsi.networkportal.add.Invoke($bind)

Exception calling "Add" with "1" argument(s): "Collection was of a fixed size."

At line:1 char:1

+ $esxcli.iscsi.networkportal.add.Invoke($bind)

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

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : DotNetMethodException

Thanks..

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you already stop/start your PS/PowerCLI session in between tries?

Which PowerCLI version are you using?


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

Reply
0 Kudos
TryllZ
Expert
Expert
Jump to solution

Now I did try that, same result.

PS C:\Users\Administrator> $esxcli = get-esxcli -v2 -vmhost (get-cluster "iSCSI_Cluster" | get-vmhost)

PS C:\Users\Administrator> $bind = @{

>>   adapter = 'vmhba65'

>>   force = $true

>>   nic = 'vmk3'

>> }

PS C:\Users\Administrator> $esxcli.iscsi.networkportal.add.Invoke($bind)

Exception calling "Add" with "1" argument(s): "Collection was of a fixed size."

At line:1 char:1

+ $esxcli.iscsi.networkportal.add.Invoke($bind)

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

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : DotNetMethodException

As for PowerCLI version :

PowerCLI Version

----------------

   VMware PowerCLI 11.3.0 build 13990089

---------------

Component Versions

---------------

   VMware Cis Core PowerCLI Component PowerCLI Component 11.3 build 13964830

   VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 11.3 build 13964826

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

What does this return?

$esxcli.iscsi.networkportal.add.CreateArgs()


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

Reply
0 Kudos
TryllZ
Expert
Expert
Jump to solution

It returns the following :

PS C:\Users\Administrator> $esxcli.iscsi.networkportal.add.CreateArgs()

Method invocation failed because [System.Management.Automation.PSMethod] does not contain a method named 'CreateArgs'.

At line:1 char:1

+ $esxcli.iscsi.networkportal.add.CreateArgs()

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

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

    + FullyQualifiedErrorId : MethodNotFound

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I assume that your cluster has more than 1 ESXi node?

In that case, and provided you want to do that action on each node in the cluster, you should do

Get-Cluster "iSCSI_Cluster" | Get-VMHost |

ForEach-Object -Process {

    $esxcli = Get-EsxCli -V2 -VMHost $_

    $bind = @{

        adapter = 'vmhba65'

        force = $true

        nic = 'vmk3'

    }

    $esxcli.iscsi.networkportal.add.Invoke($bind)

}

In your case, the $esxcli variable will be an array, and that is why those calls don't work.


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

Reply
0 Kudos
TryllZ
Expert
Expert
Jump to solution

HI LucD,

Apologies for not bringing that up, yes it had more than 1 ESXi host.

Thanks once again.

Reply
0 Kudos
TryllZ
Expert
Expert
Jump to solution

Hi,

I managed to get the connections done for the iSCSI, however, even after connecting using the Dynamic Address (-Type Send IP via PowerCLI) Address and rescanning the HBA the connection is not established, still shows in the Server Manager iSCSI Storage windows as Not Connected and I could not find anything that causes the connection to be established automatically in the powerCLi reference online, and the disk does not reflect in the LUN in PowerCLI either as shown below.

The result after PowerCLI connection configuration.

PS C:\Users\Administrator> Get-ScsiLun -VMHost $VMHosts -LunType disk

CanonicalName ConsoleDeviceName              LunType         CapacityGB MultipathPolicy

---------- -----------------              -------         ---------- ---------------

mpx.vmh... /vmfs/devices/disks/mpx.vmh... disk                 8.000 Fixed

mpx.vmh... /vmfs/devices/disks/mpx.vmh... disk                 8.000 Fixed

However, after removing the address from the Dynamic Discovery via the GUI and reentering the IP address manually the connection establishes successfully.

The result after manually establishing the connection via the GUI in vCenter.

PS C:\Users\Administrator> Get-ScsiLun -VMHost $VMHosts -LunType disk

CanonicalName ConsoleDeviceName              LunType         CapacityGB MultipathPolicy

---------- -----------------              -------         ---------- ---------------

naa.600... /vmfs/devices/disks/naa.600... disk               256.000 Fixed

naa.600... /vmfs/devices/disks/naa.600... disk               256.000 Fixed

mpx.vmh... /vmfs/devices/disks/mpx.vmh... disk                 8.000 Fixed

naa.600... /vmfs/devices/disks/naa.600... disk               256.000 Fixed

naa.600... /vmfs/devices/disks/naa.600... disk               256.000 Fixed

mpx.vmh... /vmfs/devices/disks/mpx.vmh... disk                 8.000 Fixed

Any thoughts.

Thank You

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can't you do the same with the Set-IScsiHbaTarget cmdlet and the Target parameter?
1st call, you remove the existing target, 2nd call you add it again.

This should force a rediscovery.

Btw, I suspect you might want to change/add the active vnic in between those 2 calls to Set-IScaiHbaTarget.


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

Reply
0 Kudos
TryllZ
Expert
Expert
Jump to solution

Hi LucD,

Thanks as always.

I actually did not check if the iSCSI service is started in the windows server :smileysilly:, and it was not started. Came to find that out after using the second command below.

Started service using : Start-Service msiscsi

And updated using : Update-IscsiTarget

Working now.

Thanks once again.

Reply
0 Kudos