Hi,
All I am looking for good script to help me pull out DVS switch details along with portgroup configuration. I was able to pull out IP details so may not required in script.
What Teaming and failover policy is configured.
Which NIC is set to active/standby
To which host what portgroup/switch is connected to
vlan
I am running vsphere 6.5 ,with esxi 6.5 hosted on them.
LucD Many thanks in advance.
Regards
bansne
You mean like this?
$report = @()
foreach($vds in Get-VDSwitch){
foreach($vdsPG in Get-VDPortgroup -VDSwitch $vds){
if($vdsPG.ExtensionData.Config.DefaultPortConfig.Vlan -is [VMware.Vim.VmwareDistributedVirtualSwitchPvlanSpec]){
$VLANType = "PVLan"
$VLANId = $vdsPG.ExtensionData.Config.DefaultPortConfig.Vlan.PvlanId
}
elseif($vdsPG.ExtensionData.Config.DefaultPortConfig.Vlan -is [VMware.Vim.VmwareDistributedVirtualSwitchTrunkVlanSpec]){
$VLANType = "VLAN Trunking"
$VLANId = [string]::Join(',',($vdsPG.ExtensionData.Config.DefaultPortConfig.Vlan.VlanId | %{[string]$_.Start + "-" + [string]$_.End}))
}
else{
$VLANType = "None"
$VLANId = ''
}
$report += [PSCustomObject]@{
VDS = $vds.Name
VDSESXi = (Get-View -Id $vds.ExtensionData.Summary.HostMember -Property Name).Name.Split('.').Name -join '|'
VDSTeamingPolicy = &{switch($vds.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.Policy.Value){
'failover_explicit' {'Use explicit failover order'}
'loadbalance_ip' {'Route based on IP hash'}
'loadbalance_loadbased' {'Route based on physical NIC load'}
'loadbalance_srcid' {'Route based on originating virtual port'}
'loadbalance_srcmac' {'Route based on source MAC hash'}
Default {'na'}
}}
VDSActiveUplinkPort = $vds.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.UplinkPortOrder.ActiveUplinkPort -join '|'
VDSStandbyUplinkPort = $vds.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.UplinkPortOrder.StandbylinkPort -join '|'
VDSPortgroup = $vdsPG.Name
VDSPGBinding = $vdsPG.PortBinding
VDSPGNumberOfPorts = $vdsPG.NumPorts
VLANType = $VLANType
VLANId = $VLANId
VDSPGTeamingPolicy = &{switch($vdsPG.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.Policy.Value){
'failover_explicit' {'Use explicit failover order'}
'loadbalance_ip' {'Route based on IP hash'}
'loadbalance_loadbased' {'Route based on physical NIC load'}
'loadbalance_srcid' {'Route based on originating virtual port'}
'loadbalance_srcmac' {'Route based on source MAC hash'}
Default {'na'}
}}
VDSPGTeamingPolicyInherited = $vdsPG.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.Policy.Inherited
VDSPGActiveUplinkPort = $vdsPG.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.UplinkPortOrder.ActiveUplinkPort -join '|'
VDSPGStandbyUplinkPort = $vdsPG.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.UplinkPortOrder.StandbylinkPort -join '|'
VDSPGUplinkPortInherited = $vdsPG.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.UplinkPortOrder.Inherited
vdspgAllowPromiscuous = $vdsPG.ExtensionData.Config.DefaultPortConfig.SecurityPolicy.AllowPromiscuous.Value
vdsPGMACChanges = $vdsPG.ExtensionData.Config.DefaultPortConfig.SecurityPolicy.MacChanges.Value
vdsPGForgedTransmits = $vdsPG.ExtensionData.Config.DefaultPortConfig.SecurityPolicy.AllowPromiscuous.Value
}
}
}
$report
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This could be a start.
Note that linking Uplink ports to vmnics is done per ESXi node.
How do you think this could be presented in the report (and avoiding redundant data)?
$report = @()
foreach($vds in Get-VDSwitch){
foreach($vdsPG in Get-VDPortgroup -VDSwitch $vds){
if($vdsPG.ExtensionData.Config.DefaultPortConfig.Vlan -is [VMware.Vim.VmwareDistributedVirtualSwitchPvlanSpec]){
$VLANType = "PVLan"
$VLANId = $vdsPG.ExtensionData.Config.DefaultPortConfig.Vlan.PvlanId
}
elseif($vdsPG.ExtensionData.Config.DefaultPortConfig.Vlan -is [VMware.Vim.VmwareDistributedVirtualSwitchTrunkVlanSpec]){
$VLANType = "VLAN Trunking"
$VLANId = [string]::Join(',',($vdsPG.ExtensionData.Config.DefaultPortConfig.Vlan.VlanId | %{[string]$_.Start + "-" + [string]$_.End}))
}
else{
$VLANType = "None"
$VLANId = ''
}
$report += [PSCustomObject]@{
VDS = $vds.Name
VDSESXi = (Get-View -Id $vds.ExtensionData.Summary.HostMember -Property Name).Name.Split('.').Name -join '|'
VDSTeamingPolicy = $vds.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.Policy.Value
VDSActiveUplinkPort = $vds.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.UplinkPortOrder.ActiveUplinkPort -join '|'
VDSStandbyUplinkPort = $vds.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.UplinkPortOrder.StandbylinkPort -join '|'
VDSPortgroup = $vdsPG.Name
VDSPGBinding = $vdsPG.PortBinding
VDSPGNumberOfPorts = $vdsPG.NumPorts
VLANType = $VLANType
VLANId = $VLANId
VDSPGTeamingPolicy = $vdsPG.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.Policy.Value
VDSPGTeamingPolicyInherited = $vdsPG.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.Policy.Inherited
VDSPGActiveUplinkPort = $vdsPG.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.UplinkPortOrder.ActiveUplinkPort -join '|'
VDSPGStandbyUplinkPort = $vdsPG.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.UplinkPortOrder.StandbylinkPort -join '|'
VDSPGUplinkPortInherited = $vdsPG.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.UplinkPortOrder.Inherited
vdspgAllowPromiscuous = $vdsPG.ExtensionData.Config.DefaultPortConfig.SecurityPolicy.AllowPromiscuous.Value
vdsPGMACChanges = $vdsPG.ExtensionData.Config.DefaultPortConfig.SecurityPolicy.MacChanges.Value
vdsPGForgedTransmits = $vdsPG.ExtensionData.Config.DefaultPortConfig.SecurityPolicy.AllowPromiscuous.Value
}
}
}
$report
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi ,
I agree to your statement for it being redundant data , I am ok with what I will get on current basis.
Also , I ran the script I could see it showing loadbalance_srcid/loadbased for VDS Teaming policy (is it retrieving it what's on switch level) , is there anyway I it can pull out info what is configured on portgroup level. I see NIC teaming and failover configured as "Route based on IP hash or virtual port IP" on few . if there is separate way to pull out its ok ,I can have them clubbed to info I got from above script.
I know this is too much to ask but if not this I may have to check all 100+ portgroups separately if configured correctly. I need to compare it to other vcenter in place before bringing new one live.
Those are retrieved on the Portgroup level (all properties that have PG in their name are from the Portgroup).
Not sure what you mean with "portgroups separately".
Could you perhaps give a mock-up of the report layout as you want to see it?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
Something like this, last column to be more descriptive.
You mean like this?
$report = @()
foreach($vds in Get-VDSwitch){
foreach($vdsPG in Get-VDPortgroup -VDSwitch $vds){
if($vdsPG.ExtensionData.Config.DefaultPortConfig.Vlan -is [VMware.Vim.VmwareDistributedVirtualSwitchPvlanSpec]){
$VLANType = "PVLan"
$VLANId = $vdsPG.ExtensionData.Config.DefaultPortConfig.Vlan.PvlanId
}
elseif($vdsPG.ExtensionData.Config.DefaultPortConfig.Vlan -is [VMware.Vim.VmwareDistributedVirtualSwitchTrunkVlanSpec]){
$VLANType = "VLAN Trunking"
$VLANId = [string]::Join(',',($vdsPG.ExtensionData.Config.DefaultPortConfig.Vlan.VlanId | %{[string]$_.Start + "-" + [string]$_.End}))
}
else{
$VLANType = "None"
$VLANId = ''
}
$report += [PSCustomObject]@{
VDS = $vds.Name
VDSESXi = (Get-View -Id $vds.ExtensionData.Summary.HostMember -Property Name).Name.Split('.').Name -join '|'
VDSTeamingPolicy = &{switch($vds.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.Policy.Value){
'failover_explicit' {'Use explicit failover order'}
'loadbalance_ip' {'Route based on IP hash'}
'loadbalance_loadbased' {'Route based on physical NIC load'}
'loadbalance_srcid' {'Route based on originating virtual port'}
'loadbalance_srcmac' {'Route based on source MAC hash'}
Default {'na'}
}}
VDSActiveUplinkPort = $vds.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.UplinkPortOrder.ActiveUplinkPort -join '|'
VDSStandbyUplinkPort = $vds.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.UplinkPortOrder.StandbylinkPort -join '|'
VDSPortgroup = $vdsPG.Name
VDSPGBinding = $vdsPG.PortBinding
VDSPGNumberOfPorts = $vdsPG.NumPorts
VLANType = $VLANType
VLANId = $VLANId
VDSPGTeamingPolicy = &{switch($vdsPG.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.Policy.Value){
'failover_explicit' {'Use explicit failover order'}
'loadbalance_ip' {'Route based on IP hash'}
'loadbalance_loadbased' {'Route based on physical NIC load'}
'loadbalance_srcid' {'Route based on originating virtual port'}
'loadbalance_srcmac' {'Route based on source MAC hash'}
Default {'na'}
}}
VDSPGTeamingPolicyInherited = $vdsPG.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.Policy.Inherited
VDSPGActiveUplinkPort = $vdsPG.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.UplinkPortOrder.ActiveUplinkPort -join '|'
VDSPGStandbyUplinkPort = $vdsPG.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.UplinkPortOrder.StandbylinkPort -join '|'
VDSPGUplinkPortInherited = $vdsPG.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.UplinkPortOrder.Inherited
vdspgAllowPromiscuous = $vdsPG.ExtensionData.Config.DefaultPortConfig.SecurityPolicy.AllowPromiscuous.Value
vdsPGMACChanges = $vdsPG.ExtensionData.Config.DefaultPortConfig.SecurityPolicy.MacChanges.Value
vdsPGForgedTransmits = $vdsPG.ExtensionData.Config.DefaultPortConfig.SecurityPolicy.AllowPromiscuous.Value
}
}
}
$report
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
You are genius! Thanks this is what I was looking for.
Regards
Do you have a similar script to extract all of this information for a standard switch? I saw this thread PowerCLI to extract all vSwitch network info to... |VMware Communities but what I am looking for is a CSV file that will list the following for every host:
- vSwitch Name
- List all port groups
- Which VMNIC's are configured
- Adapter failover order for each port group
- Type of traffic allowed on each port group (vMotion, FT, Management, iSCSI Port Binding)
- Security Tab (Promiscuous Mode, MAC Address Changes, Forged Transmits)
Essentially what I'm trying to do is understand how each vSwitch is configured so that I can standardize if any are not configured the same
I suggest you create a new thread for that.
Otherwise the thread title does not really cover what is in here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Do i need change any parameter in scripts ? It throws an error
PS C:\temp> .\Network-vDS_Details.ps1
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 C:\temp\Network-vDS_Details.ps1:37 char:37
+ ... VDSESXi = (Get-View -Id $vds.ExtensionData.Summary.HostMember -Proper ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-View], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInte
rop.GetVIView
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 C:\temp\Network-vDS_Details.ps1:37 char:37
+ ... VDSESXi = (Get-View -Id $vds.ExtensionData.Summary.HostMember -Proper ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-View], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInte
rop.GetVIView
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 C:\temp\Network-vDS_Details.ps1:37 char:37
+ ... VDSESXi = (Get-View -Id $vds.ExtensionData.Summary.HostMember -Proper ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-View], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInte
rop.GetVIView
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 C:\temp\Network-vDS_Details.ps1:37 char:37
+ ... VDSESXi = (Get-View -Id $vds.ExtensionData.Summary.HostMember -Proper ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-View], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInte
rop.GetVIView
Thanks
vmk
That line tries to get the ESXi nodes that are connected to that VDS.
There might be something wrong with that membership on that specific VDS.
Can you check if this returns results without errors?
Get-VDSwitch | Select Name
Get-VDSwitch | Get-VMHost | Select Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
It's returning results without any error.
PS C:\> Get-VDSwitch | Select Name
Name
----
LNC_dvSwitch1
W60x-dvSwitch
WPOD1-dvSwitch
Dublin_ESX5-dvSwitch
Dublin_DMZ_dvSwitch
Dublin_DCFW_dvSwitch
Wind DCFW - dvSwitch
Wind-DMZ-dvSwitch
dvSwitchECC
dvSwitch2GEN
Pod2-dvSwitch1
WinDerStretch_dvSwitch1
PS C:\>
PS C:\> Get-VDSwitch | Get-VMHost | Select Name
Name
----
cwb-esx22.ku.com
cwc-esx21.ku.com
cwd-esx25.ku.com
cwe-esx26.ku.com
thanks
vmk
Can you also check the following?
Get-VDSwitch | Select Name,
@{N='Connected VMHost';E={$_.ExtensionData.Summary.HostMember.Count}},
@{N='VMHost MoRef';E={$_.ExtensionData.Summary.HostMember.Value -join '|'}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Please find the output below.
Name Connected VMHost VMHost MoRef
---- ---------------- ------------
MNG_dvSwitch1 0
Z50x-dvSwitch 2 host-13742|host-18083
ZPOD1-dvSwitch 3 host-16685|host-16696|host-2519
Dublin_ESX5-dvSwitch 32 host-683971|host-683962|host-321260|host-682071|host-683979|host-684004|hos...
Dublin_DMZ_dvSwitch 2 host-1096469|host-1096473
Dublin_DCFW_dvSwitch 2 host-16073|host-16004
Wind DCFW - dvSwitch 2 host-16396|host-16118
Wind-DMZ-dvSwitch 4 host-16391|host-16107|host-1100991|host-1100996
dvSwitchESCC 0
dvSwitch2GEN 0
Prod2-dvSwitch1 51 host-48411|host-967739|host-48407|host-48427|host-16247|host-683855|host-11...
ZinBerStretch_dvSwitch1 2 host-889081|host-884383
Thanks
vmk
Ok, you seem to have a couple of VDS that have no ESXi nodes connected.
Try this version of the script
$report = @()
foreach($vds in Get-VDSwitch){
foreach($vdsPG in Get-VDPortgroup -VDSwitch $vds){
if($vdsPG.ExtensionData.Config.DefaultPortConfig.Vlan -is [VMware.Vim.VmwareDistributedVirtualSwitchPvlanSpec]){
$VLANType = "PVLan"
$VLANId = $vdsPG.ExtensionData.Config.DefaultPortConfig.Vlan.PvlanId
}
elseif($vdsPG.ExtensionData.Config.DefaultPortConfig.Vlan -is [VMware.Vim.VmwareDistributedVirtualSwitchTrunkVlanSpec]){
$VLANType = "VLAN Trunking"
$VLANId = [string]::Join(',',($vdsPG.ExtensionData.Config.DefaultPortConfig.Vlan.VlanId | %{[string]$_.Start + "-" + [string]$_.End}))
}
else{
$VLANType = "None"
$VLANId = ''
}
$report += [PSCustomObject]@{
VDS = $vds.Name
VDSESXi = &{
if($vds.ExtensionData.Summary.HostMember){
(Get-View -Id $vds.ExtensionData.Summary.HostMember -Property Name).Name.Split('.').Name -join '|'
}}
VDSTeamingPolicy = &{switch($vds.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.Policy.Value){
'failover_explicit' {'Use explicit failover order'}
'loadbalance_ip' {'Route based on IP hash'}
'loadbalance_loadbased' {'Route based on physical NIC load'}
'loadbalance_srcid' {'Route based on originating virtual port'}
'loadbalance_srcmac' {'Route based on source MAC hash'}
Default {'na'}
}}
VDSActiveUplinkPort = $vds.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.UplinkPortOrder.ActiveUplinkPort -join '|'
VDSStandbyUplinkPort = $vds.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.UplinkPortOrder.StandbylinkPort -join '|'
VDSPortgroup = $vdsPG.Name
VDSPGBinding = $vdsPG.PortBinding
VDSPGNumberOfPorts = $vdsPG.NumPorts
VLANType = $VLANType
VLANId = $VLANId
VDSPGTeamingPolicy = &{switch($vdsPG.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.Policy.Value){
'failover_explicit' {'Use explicit failover order'}
'loadbalance_ip' {'Route based on IP hash'}
'loadbalance_loadbased' {'Route based on physical NIC load'}
'loadbalance_srcid' {'Route based on originating virtual port'}
'loadbalance_srcmac' {'Route based on source MAC hash'}
Default {'na'}
}}
VDSPGTeamingPolicyInherited = $vdsPG.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.Policy.Inherited
VDSPGActiveUplinkPort = $vdsPG.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.UplinkPortOrder.ActiveUplinkPort -join '|'
VDSPGStandbyUplinkPort = $vdsPG.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.UplinkPortOrder.StandbylinkPort -join '|'
VDSPGUplinkPortInherited = $vdsPG.ExtensionData.Config.DefaultPortConfig.UplinkTeamingPolicy.UplinkPortOrder.Inherited
vdspgAllowPromiscuous = $vdsPG.ExtensionData.Config.DefaultPortConfig.SecurityPolicy.AllowPromiscuous.Value
vdsPGMACChanges = $vdsPG.ExtensionData.Config.DefaultPortConfig.SecurityPolicy.MacChanges.Value
vdsPGForgedTransmits = $vdsPG.ExtensionData.Config.DefaultPortConfig.SecurityPolicy.AllowPromiscuous.Value
}
}
}
$report
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Cant we export into CSV format ?
thanks
vmk
Change the last line to
$report | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD. i did. It was simple.
thanks
vmk
LucD,
It worked for me. Let me know how to mark as correct.
Thanks
vmk
This thread was already marked as Answered.
You can only assign Helpful afaik, but that's ok, no problem.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference