Your foreach loops were not correct.
Try it perhaps like this
#Define some variables
$vcServer = "xxxxx"
$cluster = "DEV_Cluster"
$esxcred = import-pscredential -Path D:\VMwebsite\Vmware\password\ESX.enc.xml
$vccred = import-pscredential -Path D:\VMwebsite\Vmware\password\VCentre.enc.xml
$filelocation = "C:\Myscripts\Scripts\VMUplinks.csv"
$Report = @()
#Connect to vCenter
Connect-VIServer $vcServer -Credential $vccred | Out-Null
#Connect to ESX hosts in cluster
foreach ($esx in Get-Cluster $cluster | Get-VMHost) {
Connect-VIServer $esx -Credential $esxCred
#Retrieve the esxcli instances and loop through them
foreach($esxcli in (Get-EsxTop -CounterName netport)) {
$NetworkInfo = "" | select-Object HostName , VMName , Uplink
$NetworkInfo.HostName = $esx.Name
$NetworkInfo.VMName = $esxcli.ClientName
$NetworkInfo.Uplink = $esxcli.TeamUplink
$Report += $NetworkInfo
}
#Disconnect from ESX host
Disconnect-VIServer $esx.name -Confirm:$false
}
$Report | Export-CSV $filelocation
#Disconnect from vCenter
Disconnect-VIServer $vcServer -Confirm:$false | Out-Null