I would like to be able to set NetworkName in the NetworkAdapter, but obtaining this data from the "VLAN ID". In the script you should enter the "VLAN ID" set the NetworkName in the NetworkAdapter. I already have everything set up, but I only need the part to get the NetworkName from the "VLAN ID".
In any case, the following will find the networkname of the PG with corresponding VlanId.
And it works for VSS and VDS.
Get-VirtualPortGroup -PipelineVariable pg |
ForEach-Object -Process {
$vlanId = if($pg -is [VMware.VimAutomation.ViCore.Types.V1.Host.Networking.DistributedPortGroup]){
if($pg.ExtensionData.Config.DefaultPortConfig.Vlan -is [VMware.Vim.VmwareDistributedVirtualSwitchPvlanSpec]){
$pg.ExtensionData.Config.DefaultPortConfig.Vlan.PvlanId
}
elseif($pg.ExtensionData.Config.DefaultPortConfig.Vlan -is [VMware.Vim.VmwareDistributedVirtualSwitchVlanSpec]){
if($pg.ExtensionData.Config.DefaultPortConfig.Vlan.VlanId -is [VMware.Vim.NumericRange[]]){
[string]::Join(',',($_.ExtensionData.Config.DefaultPortConfig.Vlan.VlanId | %{"$($_.Start)-$($_.End)"}))
}
else{
$pg.ExtensionData.Config.DefaultPortConfig.Vlan.VlanId
}
}
}
else{$pg.VlanId}
if($vlanId -eq $tgtVlanId){
$pg.Name
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You mean like this?
Get-VirtualPortGroup | where{$_.VlanId -eq $vlanId} | select -ExpandProperty Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I tried several vlanID's and it doesn't bring me data
Are you using VSS or VDS?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
In any case, the following will find the networkname of the PG with corresponding VlanId.
And it works for VSS and VDS.
Get-VirtualPortGroup -PipelineVariable pg |
ForEach-Object -Process {
$vlanId = if($pg -is [VMware.VimAutomation.ViCore.Types.V1.Host.Networking.DistributedPortGroup]){
if($pg.ExtensionData.Config.DefaultPortConfig.Vlan -is [VMware.Vim.VmwareDistributedVirtualSwitchPvlanSpec]){
$pg.ExtensionData.Config.DefaultPortConfig.Vlan.PvlanId
}
elseif($pg.ExtensionData.Config.DefaultPortConfig.Vlan -is [VMware.Vim.VmwareDistributedVirtualSwitchVlanSpec]){
if($pg.ExtensionData.Config.DefaultPortConfig.Vlan.VlanId -is [VMware.Vim.NumericRange[]]){
[string]::Join(',',($_.ExtensionData.Config.DefaultPortConfig.Vlan.VlanId | %{"$($_.Start)-$($_.End)"}))
}
else{
$pg.ExtensionData.Config.DefaultPortConfig.Vlan.VlanId
}
}
}
else{$pg.VlanId}
if($vlanId -eq $tgtVlanId){
$pg.Name
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That's right, I use VDS
It worked perfect, thank you very much