We are implementing distributed switches in our environment, we are trying to migrate using powercli and it works great.
My question is purely cosmetic. Is it possible to rename the different uplinks via powercli? I haven't found anything to do so.
Now it's dvuplink1, ... and so on, but we want to have meaningful names to it, saying to which networks this is an uplink and even mention the group to which it is connected on our core switch, for quicker troubleshooting.
Try something like this
$vdsName = 'vds1'
$oldUplinkName = 'dvUplink'
$newUplinkName = 'MyUplink'
$vds = Get-VDSwitch -Name $vdsName
$spec = New-Object VMware.Vim.DVSConfigSpec
$spec.ConfigVersion = $vds.ExtensionData.Config.ConfigVersion
$spec.UplinkPortPolicy = New-Object VMware.Vim.DVSNameArrayUplinkPortPolicy
$vds.ExtensionData.Config.UplinkPortPolicy.UplinkPortName | %{
$spec.UplinkPortPolicy.UplinkPortName += $_.Replace($oldUplinkName,$newUplinkName)
}
$vds.ExtensionData.ReconfigureDvs($spec)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It is possible to rename the uplink ports but I'm not sure if this is possible with PowerCLI. Maybe you can use the Set-VDport PowerCLI cmdlet?
Try something like this
$vdsName = 'vds1'
$oldUplinkName = 'dvUplink'
$newUplinkName = 'MyUplink'
$vds = Get-VDSwitch -Name $vdsName
$spec = New-Object VMware.Vim.DVSConfigSpec
$spec.ConfigVersion = $vds.ExtensionData.Config.ConfigVersion
$spec.UplinkPortPolicy = New-Object VMware.Vim.DVSNameArrayUplinkPortPolicy
$vds.ExtensionData.Config.UplinkPortPolicy.UplinkPortName | %{
$spec.UplinkPortPolicy.UplinkPortName += $_.Replace($oldUplinkName,$newUplinkName)
}
$vds.ExtensionData.ReconfigureDvs($spec)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This seems to work. Thank you!
I now have another problem, when I try this script on Distributed switches created by powerCLI I get following error:
"The resource 'dvUplink1' is in use. Uplink or Link Aggregation group name dvUplink1 is in use by the teaming policy defined at DVPortgroup dvpg-373"
If I do this on manually created Distributed switches, the script works like a charm.
This looks like a problem described in https://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=20436.... However I am doing this on a vcenter 6.5 appliance, which is much newer than vcenter 5.5.
I found out that if you create a New Distributed Switch in vCenter 6.5 it is created with uplinks named "Uplink 1, Uplink 2,...". When I create the same switch using powerCLI, the uplinks are named "dvUplink1, dvUplink2,..." probably here in lies the problem.
Can't you test the vCenter version, and then update the content of the $oldUplinkName variable accordingly?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Most of the time that indicates there is something wrong with $spec.ConfigVersion
Can you check if the value corresponds with the one in $vds.ExtensionData.Config.ConfigVersion
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you for the quick response. Here is what I have as a test with 2 dvuplinks. Any help is appreciated.
$dvduplink1 = 'dvUplink1'
$Uplink0 = 'Uplink0"
$vds = Get-VDSwitch -Name Test-VDS
$spec = New-Object VMware.Vim.DVSConfigSpec
$spec.ConfigVersion = $vds.ExtensionData.Config.ConfigVersion
$spec.UplinkPortPolicy = New-Object VMware.Vim.DVSNameArrayUplinkPortPolicy
$vds.ExtensionData.Config.UplinkPortPolicy.UplinkPortName | %{
$spec.UplinkPortPolicy.UplinkPortName += $_.Replace($dvduplink1,$Uplink0)
}
$vds.ExtensionData.ReconfigureDvs($spec)
#
$dvduplink2 = 'dvUplink2'
$Uplink1 = 'Uplink1"
$vds = Get-VDSwitch -Name Test-VDS
$spec = New-Object VMware.Vim.DVSConfigSpec
$spec.ConfigVersion = $vds.ExtensionData.Config.ConfigVersion
$spec.UplinkPortPolicy = New-Object VMware.Vim.DVSNameArrayUplinkPortPolicy
$vds.ExtensionData.Config.UplinkPortPolicy.UplinkPortName | %{
$spec.UplinkPortPolicy.UplinkPortName += $_.Replace($dvduplink2,$Uplink1)
}
Yes, but you are using the old value (the one before the 1st call to ReconfigureDvs).
You can do them all in 1 call, something like this.
I use a hash table to lookup the new name.
$dvsLink = @{
'dvUplink1' = 'dvUplink0'
'dvUplink2' = 'dvUplink1'
'dvUplink3' = 'dvUplink4'
'dvUplink4' = 'dvUplink5'
'dvUplink5' = 'dvUplink6'
'dvUplink6' = 'dvUplink8'
}
$vds = Get-VDSwitch -Name vds1
$spec = New-Object VMware.Vim.DVSConfigSpec
$spec.ConfigVersion = $vds.ExtensionData.Config.ConfigVersion
$spec.UplinkPortPolicy = New-Object VMware.Vim.DVSNameArrayUplinkPortPolicy
$vds.ExtensionData.Config.UplinkPortPolicy.UplinkPortName | %{
$spec.UplinkPortPolicy.UplinkPortName += $dvsLink[$_]
}
$vds.ExtensionData.ReconfigureDvs($spec)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference