Hi LucD
I have a requirement where I need to get a report with the following details
Cluster name, vCenter, VMname, Portgroup and VLAN id
The below scripts works but if the VM has two Network Adaptors then i dont get the VLAN id for the 2nd adapter
Script
##################################################################
$Report =@()
$Report +=Get-cluster -PipelineVariable cluster |Get-VMHost |`
get-vm | where {$_.ExtensionData.Config.ManagedBy.extensionKey -NotLike "com.vmware.vcDr*"} |`
Select-Object @{N="vCenter"; E={$_.Uid.Split(':@')[1]}},
@{ N= 'Cluster' ; E={$cluster.Name}},
@{ N= 'VMName' ; E={$_.name}},
# @{N ='VMcount' ; E={($_| get-vm).count }},
#@{N= 'NW_Adapter1' ; E={(Get-NetworkAdapter -VM $_)[0].Name }},
@{N= 'PortGroup1' ; E={(get-networkadapter -VM $_)[0].NetworkName}},
@{N= 'VLAN1' ;E={(Get-VirtualPortGroup -VM $_).extensiondata.config.DefaultPortConfig.vlan.vlanid[0]}},
#@{N= 'NW_Adapter2' ; E={(Get-NetworkAdapter -VM $_)[1].Name }},
@{N= 'PortGroup2' ; E={(get-networkadapter -VM $_)[1].NetworkName}},
@{N= 'VLAN2' ;E={(Get-VirtualPortGroup -VM $_).extensiondata.config.DefaultPortConfig.vlan.vlanid[1]}},
#@{N= 'NW_Adapter3' ; E={(Get-NetworkAdapter -VM $_)[2].Name }},
@{N= 'PortGroup3' ; E={(get-networkadapter -VM $_)[2].NetworkName}},
@{N= 'VLAN3' ;E={(Get-VirtualPortGroup -VM $_).extensiondata.config.DefaultPortConfig.vlan.vlanid[2]}},
@{N= 'PortGroup4' ; E={(Get-NetworkAdapter -VM $_)[3].Name }},
@{N= 'VLAN4' ;E={(Get-VirtualPortGroup -VM $_).extensiondata.config.DefaultPortConfig.vlan.vlanid[3]}}
$report |Export-Csv $ReportPath -NoTypeInformation -UseCulture
Any help to fix this issue please
many thanks
RXJ