Could it be that you have multiple connections open?
What is in $global:defaultviservers?
What do you have in serverlist.txt?
Are those vCenters?
It looks as if you are overwriting your output file with each loop.
Shouldn't that be
if (Test-Path 'E:\vSphereScript\vCenterVMList.csv'){ Remove-Item 'E:\vSphereScript\vCenterVMList.csv'
}
$serverList = Get-Content -Path "E:\vSphereScript\serverlist.txt"
$report = @()
foreach ($server in $serverList) {
$creds = Get-VICredentialStoreItem -file "E:\vSphereScript\vicredentials.xml" -Host $server
Connect-VIServer -server $creds.host -user $creds.user -password $creds.password
$report += Get-VM | Select-Object Name, Guest, VMhost, ResourcePool
Disconnect-VIServer $server -Confirm:$false
}
$report | | Export-Csv -Path "E:\ProgramData\vCenterVMList.csv" -NoTypeInformation -Append
Note that behind Guest, VMhost and ResourcePool are complex objects.
What do you actually want in your output file?
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.