Hi Team,
I am trying to find the powercli script but not getting,
So here is my scenario,
1- Host has two physical nics vmnic-0 and vmnic1
2- Host are already part of the dvs behind multiple port group with uplink1- vmnic0 and uplink2-vmnic1.
Now we have configure LACP & created LAG1 & LAG2, and after this steps just wanted to connect the host in LAGs, existing one and will connect new host also, does anyone has any powercli script which can does the job?
Thanks
Try something like this
$lagName = 'mgmt-lag'
$tgtDevs = 'vmnic0', 'vmnic1'
$vds = Get-VDSwitch -Name $vdsName
$uplPg = Get-VDPortgroup -VDSwitch $vds -Name *UpLinks*
Get-View -Id $vds.ExtensionData.Summary.Host |
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)
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Discussion moved from Forums to VMware PowerCLI
Not sure exactly what you mean by "connect the host".
Do you mean the Migrating network traffic to LAGs option in the Web Client?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
ok so let elaborate you,
basically I want to add host in vds but now vds is configured with lag Instid of uplink.
Can you share a screenshot of the topology of the VDS?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Here is my VDS topology,
If you see right now all host nic are behind the uplink1 & Uplink2
Thanks
Try something like this
$lagName = 'mgmt-lag'
$tgtDevs = 'vmnic0', 'vmnic1'
$vds = Get-VDSwitch -Name $vdsName
$uplPg = Get-VDPortgroup -VDSwitch $vds -Name *UpLinks*
Get-View -Id $vds.ExtensionData.Summary.Host |
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)
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD its works for all host.
but want specific host only to move behind the lag so how can we configure using the script?
Thanks
Bharat
Try replacing
where{$_.Name -eq 'MyHost'} |
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks you Luc it works,
I have multiple Nics on my server hence can move nics based on mac address.
Thanks
Bharat
Hi Luc,
I am trying this script on the on vcenter version VMware ESXi 6.7.0 ( VMKernal Release Build 15160138) but its not working any clue where i have tried this on below vcenter version works .
Thanks
Really?!?
21 months after I provided you with a working script and where you never bothered to mark it as the correct solution.
Don't think so
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks