Hello, I use this script to get some network adapter information, I would like to get also switch too,
Get-VMHostNetworkAdapter |
Where-Object {$_.GetType().Name -eq "PhysicalNicImpl"} |
Select-Object -Property VMHost,Name,BitRatePerSec,FullDuplex,Mac,DhcpEnabled,
@{Name="AutoNegotiate";Expression={
if ($_.ExtensionData.Spec.LinkSpeed)
{$false} else {$true}
}},
@{Name="LinkState";Expression={
if ($_.ExtensionData.LinkSpeed)
{"Up"} else {"Down"}
}} | Export-Csv -Path C:\Users\gemela\info.csv -NoTypeInformation -UseCulture
Thanks
Ok, with VDS the vSwitch field is indeed blank.
Try this variation.
Select-Object -Property VMHost,Name,BitRatePerSec,FullDuplex,Mac,DhcpEnabled,
@{Name="AutoNegotiate";Expression={
if ($_.ExtensionData.Spec.LinkSpeed)
{$false} else {$true}
}},
@{Name="LinkState";Expression={
if ($_.ExtensionData.LinkSpeed)
{"Up"} else {"Down"}
}},
@{N='vSwitch';E={
$vmnic = $_.Name
$esxcli = Get-EsxCli -VMHost $_.VMHost
$sw = @($esxcli.network.vswitch.standard.list() | where{$_.Uplinks -contains $vmNic} | select -ExpandProperty Name)
$sw += $esxcli.network.vswitch.dvs.vmware.list() | where{$_.Uplinks -contains $vmNic} | select -ExpandProperty Name
$sw -join '|'}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this
Select-Object -Property VMHost,Name,BitRatePerSec,FullDuplex,Mac,DhcpEnabled,
@{Name="AutoNegotiate";Expression={
if ($_.ExtensionData.Spec.LinkSpeed)
{$false} else {$true}
}},
@{Name="LinkState";Expression={
if ($_.ExtensionData.LinkSpeed)
{"Up"} else {"Down"}
}},
@{N='vSwitch';E={
$vnic = $_.Name
Get-VirtualSwitch -VMHost $_.VMHost | where{$_.Nic -contains $vnic} | Select -ExpandProperty Name
}} | Export-Csv -Path C:\Users\gemela\info.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
vSwitch record are empty in the csv
Works for me, the vSwitch property is empty when the vmnic is not used in any vSwitch.
Are you using VSS or VDS, or a mix of both types?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ok, with VDS the vSwitch field is indeed blank.
Try this variation.
Select-Object -Property VMHost,Name,BitRatePerSec,FullDuplex,Mac,DhcpEnabled,
@{Name="AutoNegotiate";Expression={
if ($_.ExtensionData.Spec.LinkSpeed)
{$false} else {$true}
}},
@{Name="LinkState";Expression={
if ($_.ExtensionData.LinkSpeed)
{"Up"} else {"Down"}
}},
@{N='vSwitch';E={
$vmnic = $_.Name
$esxcli = Get-EsxCli -VMHost $_.VMHost
$sw = @($esxcli.network.vswitch.standard.list() | where{$_.Uplinks -contains $vmNic} | select -ExpandProperty Name)
$sw += $esxcli.network.vswitch.dvs.vmware.list() | where{$_.Uplinks -contains $vmNic} | select -ExpandProperty Name
$sw -join '|'}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This is perfect, thanks LucD.
Hi LucD,
One more question, Is possible to group the result? or get name of hardware? (one more column),
It will be useful if I can recognize which Nic is part of Broadcom 10/20 Gigabit Ethernet and which Nic are part of Intel...
Thanks a lot.
Try like this
Select-Object -Property VMHost,Name,BitRatePerSec,FullDuplex,Mac,DhcpEnabled,
@{Name="AutoNegotiate";Expression={
if ($_.ExtensionData.Spec.LinkSpeed)
{$false} else {$true}
}},
@{Name="LinkState";Expression={
if ($_.ExtensionData.LinkSpeed)
{"Up"} else {"Down"}
}},
@{N='vSwitch';E={
$script:vmnic = $_.Name
$script:esxcli = Get-EsxCli -VMHost $_.VMHost
$sw = @($esxcli.network.vswitch.standard.list() | where{$_.Uplinks -contains $vmNic} | select -ExpandProperty Name)
$sw += $esxcli.network.vswitch.dvs.vmware.list() | where{$_.Uplinks -contains $vmNic} | select -ExpandProperty Name
$sw -join '|'}},
@{N='HW';E={
$script:esxcli.network.nic.list() | where{$_.Name -eq $script:vmnic} | select -ExpandProperty Description}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Amazing, thanks LucD 🙂