VMware Cloud Community
nmbgdc
Enthusiast
Enthusiast

While Adding host in Lag getting error from powercli script

Hi Guys,

I am using the below script to add host in lag in vcenter but when i am running the script  getting below error..I dont know why i am getting this error..

Get-View : Cannot validate argument on parameter 'Id'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

At /ansible-vmware/vmwarehost-config-playbooks/uplink-vds-lag-dvs1-mac.ps1:38 char:14

+ Get-View -Id $vds.ExtensionData.Summary.Host | where{$_.Name -eq "$ne ...

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

+ CategoryInfo          : InvalidData: (:) [Get-View], ParameterBindingValidationException

+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView

##################---Script start from here----##############################################################

Connect-VIServer -Server "XXXXX" -User "XXXXXXXX" -Password "XXXX" -Force

$vdsName = 'dvs-1'

$lagName = 'lag1'

$tgtDevs = 'vmnic0', 'vmnic1'

$vds = Get-VDSwitch -Name $vdsName

$uplPg = Get-VDPortgroup -VDSwitch $vds -Name *UpLinks*

Get-View -Id  $vds.ExtensionData.Summary.Host where{$_.Name -eq 'MyHost'}  |

ForEach-Object -Process {

    $netSys = Get-View -Id $_.ConfigManager.NetworkSystem

    $lagPorts = (($netSys.NetworkInfo.ProxySwitch | where { $_.DvsUuid -eq $vds.Key }).HostLag |

        where { $_.LagName -eq $lagName }).UplinkPort.Key

    $i = 0

    $spec = New-Object VMware.Vim.HostNetworkConfig

    $proxy = New-Object VMware.Vim.HostProxySwitchConfig

    $proxy.ChangeOperation = [VMware.Vim.HostConfigChangeOperation]::edit

    $proxy.Uuid = $vds.Key

    $proxy.Spec = New-Object VMware.Vim.HostProxySwitchSpec

    $proxy.Spec.Backing = New-Object VMware.Vim.DistributedVirtualSwitchHostMemberPnicBacking

    ($netSys.NetworkInfo.ProxySwitch | where { $_.DvsUuid -eq $vds.Key }).Spec.Backing.PnicSpec |

    ForEach-Object -Process {

        if ($tgtDevs -contains $_.PnicDevice)

        {

            $pNicSpec = New-Object VMware.Vim.DistributedVirtualSwitchHostMemberPnicSpec

            $pNicSpec.PnicDevice = $_.PnicDevice

            $pNicSpec.UplinkPortKey = $lagPorts[$i]

            $pNicSpec.UplinkPortgroupKey = $uplPg.Key

            $proxy.Spec.Backing.PnicSpec += $pNicSpec

            $i++

        }

        else

        {

            $proxy.Spec.Backing.PnicSpec += $_

        }

    }

    $spec.ProxySwitch += $proxy

    $netSys.UpdateNetworkConfig($spec, [VMware.Vim.HostConfigChangeMode]::modify)

}

Thanks

Tags (2)
Reply
0 Kudos
14 Replies
LucD
Leadership
Leadership

Do you have any ESXi nodes added to that VDS?


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

Reply
0 Kudos
nmbgdc
Enthusiast
Enthusiast

Yes Luc, it is already there and same host  migrating from uplink to lag.. only thing is that I have remove the host from DVS. added it again..

Reply
0 Kudos
LucD
Leadership
Leadership

And are you sure that Get-VDSwitch is returning an object?

Something is $null in the subsequent Get-View, at least that is what the error message states


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

Reply
0 Kudos
nmbgdc
Enthusiast
Enthusiast

You are right I am not getting any output from the get-view

PS /vmware> $vdsName = "dvs-1"

PS /vmware> $lagName = "lag1"

PS /vmware> $vds = Get-VDSwitch -Name $vdsName

PS /vmware> $vds

Name                           NumPorts   Mtu        Version  Vendor

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

dvs-1                          12         1500       6.5.0    VMware, Inc.

PS /ansible-vmware/vmwarehost-config-playbooks> Get-View -Id $vds.ExtensionData.Summary.Host | where{$_.Name -eq "myhost-01.examlab.com"}

Get-View : Cannot validate argument on parameter 'Id'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

At line:1 char:14

+ Get-View -Id $vds.ExtensionData.Summary.Host | where{$_.Name -eq "myh ...

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

+ CategoryInfo          : InvalidData: (:) [Get-View], ParameterBindingValidationException

+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView

but if you see below i can see host in DVS from vcenter console but details not getting from Powercli...and i have observe this happens only when you remove the host from the DVS and add it back in the DVS and then your try again to migrate to lag..

Vcenter.PNG

Thanks

Reply
0 Kudos
LucD
Leadership
Leadership

Those vmnic on the uplinks seem to not be connected.

Are they offline/disabled?


Is the following returning anything?

Get-VDSwitch | Get-VMHost


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

Reply
0 Kudos
nmbgdc
Enthusiast
Enthusiast

Yes they are disconnected.

and here is the output of the command

PS /vmware> Get-VDSwitch | Get-VMHost

Name                 ConnectionState PowerState NumCpu CpuUsageMhz CpuTotalMhz   MemoryUsageGB   MemoryTotalGB Version

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

myhost-01.examlab.c… Connected       PoweredOn      48          74      100560           6.677         767.679   6.7.0

Thanks

Reply
0 Kudos
LucD
Leadership
Leadership

And which object(s) are produced by

Get-View -Id $vds.ExtensionData.Summary.Host

plus, what is in there?

$vds.ExtensionData.Summary.Host


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

Reply
0 Kudos
nmbgdc
Enthusiast
Enthusiast

check this, it is start of the script.

PS /vmware> $vdsName = "dvs-1"

PS /vmware> $lagName = "lag1"

PS /vmware> $vds = Get-VDSwitch -Name $vdsName

PS /vmware> $vds

Name                           NumPorts   Mtu        Version  Vendor

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

dvs-1                          12         1500       6.5.0    VMware, Inc.

PS /vmware> Get-View -Id $vds.ExtensionData.Summary.Host | where{$_.Name -eq "myhost-01.examlab.com"}

Get-View : Cannot validate argument on parameter 'Id'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

At line:1 char:14

+ Get-View -Id $vds.ExtensionData.Summary.Host | where{$_.Name -eq "myh ...

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

+ CategoryInfo          : InvalidData: (:) [Get-View], ParameterBindingValidationException

+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView

Reply
0 Kudos
LucD
Leadership
Leadership

That is not answering the 2nd part of my question.


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

Reply
0 Kudos
nmbgdc
Enthusiast
Enthusiast

Hi,

Are you looking for the output of this command $vds.ExtensionData.Summary.Host ? if yes then there is no output its blank..

and if my understanding is not correct please tell me list what exactly you are looking for will share the details accordingly.

Thanks

Reply
0 Kudos
LucD
Leadership
Leadership

No, that is what I was looking for.

So there are apparently no ESXi nodes added to the VDS.


I would say your VDS is in a funny state, since it does show vmnic (although offline) configured on the uplinks of the VDS.

I would suggest you first fix that issue.


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

Reply
0 Kudos
nmbgdc
Enthusiast
Enthusiast

sure will try to fix that or may be will use another host.

Actually  i was using powershell to add host in VDS and assign the uplinks,

and using the above script migrating the uplinks to lag..

In this case its two step process, however can we do it in single steps & how could you please suggest?

Here i have tried same thing on the different host..but result is the same.. and this host is already in the VDS and Lag then also i am getting blank value and i dont if this is the default behavior

Get-View -Id $vds.ExtensionData.Summary.Host | where{$_.Name -eq "vm01.examlab.com"}

vcenter-2.PNG

PS /vmware> Get-View -Id $vds.ExtensionData.Summary.Host | where{$_.Name -eq "vm01.examlab.com"}

Get-View : Cannot validate argument on parameter 'Id'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

At line:1 char:14

+ Get-View -Id $vds.ExtensionData.Summary.Host | where{$_.Name -eq "vm0 ...

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

+ CategoryInfo          : InvalidData: (:) [Get-View], ParameterBindingValidationException

+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView

Thanks

Reply
0 Kudos
LucD
Leadership
Leadership

So now you want me to provide you a script to fix your issue from How to check host if already added in VDSwitch? (where you never bothered to reply) as well?

Don't think so, first get a working VDS.


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

Reply
0 Kudos
nmbgdc
Enthusiast
Enthusiast

Don't assume that, i have just ask if you can suggest since we are not the creator of the vmware product we are just user...its you wish if you want to help its fine if doesnot want to help that is also fine...please dont be so rude.

In the other thread i have very clearly given my script which work as per my expectation hence shared...so where i have not bothered to answers could you please let me know..

and where you have said that it required APIs to work...

Thanks

Reply
0 Kudos