$netAdapters = @(Get-NetAdapter -IncludeHidden) $report = @(Get-VMNetworkAdapter -All | ForEach-Object { $nic = $_ $vlan = $nic | Get-VMNetworkAdapterVlan $nicName = $nic.Name if ($nic.IsManagementOS) { $netAdapter = $netAdapters | Where-Object { ($_.MacAddress -replace '[-:]', '') -eq ($nic.MacAddress -replace '[-:]', '') } | Select-Object -First 1 if ($netAdapter) { $nicName = $netAdapter.Name if ($netAdapter.Status -eq 'Up') { $nicConnected = $True } else { $nicConnected = $False } } else { $nicConnected = $nic.Connected } } [PSCustomObject]@{ ComputerName = $nic.ComputerName OwnerType = if ($nic.IsManagementOS) { 'HostOS' } else { 'VM' } IsManagementOS = $nic.IsManagementOS VMName = $nic.VMName VMId = $nic.VMId NICName = $nicName MacAddress = $nic.MacAddress IsLegacy = $nic.IsLegacy IsSynthetic = $nic.IsSynthetic Connected = $nicConnected SwitchName = $nic.SwitchName SwitchId = $nic.SwitchId VlanMode = $vlan.OperationMode AccessVlanId = $vlan.AccessVlanId NativeVlanId = $vlan.NativeVlanId AllowedVlanIds = $vlan.AllowedVlanIdList -join ',' PrimaryVlanId = $vlan.PrimaryVlanId SecondaryVlanId = $vlan.SecondaryVlanId SecondaryVlanIds = $vlan.SecondaryVlanIdList -join ',' } }) $fileName = '.\VMNetListReport-{0}-{1}.csv' -f $env:COMPUTERNAME, (Get-Date -Format 'yyyyMMdd-HHmmss') $report | Export-Csv -Path $fileName -NoTypeInformation -Encoding UTF8 $report Write-Host "CSV out to: $($fileName)"