How can I find the first vmnic with powerCLI that is not being used by any of the virtual switches on a host? I am not concerned if it is connected or not.
Something like this ?
It will list all the pnic and then remove the ones used in vSwitch or dvSwitch.
$nicTab = @{} $esx = Get-VMHost MyEsx
$esx.ExtensionData.Config.Network.Pnic | %{ $nicTab.Add($_.Key,$_.Device) } # Regular switches
$esx.ExtensionData.Config.Network.Vswitch | %{ $_.Pnic | %{ $nicTab.Remove($_) } } # dvSwitches
$esx.ExtensionData.Config.Network.ProxySwitch | %{ $_.Pnic | %{ $nicTab.Remove($_) } } # What is left ?
$nicTab.GetEnumerator()
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Something like this ?
It will list all the pnic and then remove the ones used in vSwitch or dvSwitch.
$nicTab = @{} $esx = Get-VMHost MyEsx
$esx.ExtensionData.Config.Network.Pnic | %{ $nicTab.Add($_.Key,$_.Device) } # Regular switches
$esx.ExtensionData.Config.Network.Vswitch | %{ $_.Pnic | %{ $nicTab.Remove($_) } } # dvSwitches
$esx.ExtensionData.Config.Network.ProxySwitch | %{ $_.Pnic | %{ $nicTab.Remove($_) } } # What is left ?
$nicTab.GetEnumerator()
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
Thank you for your Scrips.
Do you have any update for this scrips?
How can I see the vSwitchs and DVswitchs with their vmnics?
Thank you.
Try something like this
Get-View -ViewType HostSystem -PipelineVariable esx |
ForEach-Object -Process {
$netSys = Get-View -Id $esx.ConfigManager.NetworkSystem
foreach($vss in $netSys.NetworkInfo.Vswitch){
foreach($nic in $vss.Pnic){
$netSys.NetworkInfo.Pnic | where{$_.Key -eq $nic} |
Select @{N='VMHost';E={$esx.Name}},
@{N='Switch';E={$vss.Name}},
@{N='SwitchType';E={'VSS'}},
@{N='pNic';E={$_.Device}}
}
}
foreach($vds in $netSys.NetworkInfo.ProxySwitch){
foreach($nic in $vds.Spec.Backing.PnicSpec){
$netSys.NetworkInfo.Pnic | where{$_.Device -eq $nic.PnicDevice} |
Select @{N='VMHost';E={$esx.Name}},
@{N='Switch';E={$vds.DvsName}},
@{N='SwitchType';E={'VDS'}},
@{N='pNic';E={$_.Device}}
}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you LucD.
Thank you so much LucD.
Could you tell me what is the problem?
Thank you for your answer.
Looks like you might have switches with no pNICs connected.
Add a test for that.
$esx = Get-VMHost MyEsx
$esx.ExtensionData.Config.Network.Pnic | %{
$nicTab.Add($_.Key,$_.Device)
}
# Regular switches
$esx.ExtensionData.Config.Network.Vswitch | %{
$_.Pnic | %{
if($_){
$nicTab.Remove($_)
}
}
}
# dvSwitches
$esx.ExtensionData.Config.Network.ProxySwitch | %{
$_.Pnic | %{
if($_){
$nicTab.Remove($_)
}
}
}
# What is left ?
$nicTab.GetEnumerator()
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you so much LucD.