Hello, sas23-
You were quite close. The main thing was to move the Export-CSV call outside of the foreach loop like:
$VMs = "vm1", "vm2", "vm3"
&{foreach ($i in $VMs) {
Get-VM $i | Select-Object -Property Name,
@{N="DNS Name";E={$_.ExtensionData.Guest.HostName}},
PowerState,numCPU,MemoryMB,Version,
Id,ProvisionedSpaceGB,UsedSpaceGB,VMHost,
@{N="ToolsVersion";E={$_.ExtensionData.Config.Tools.ToolsVersion}},
@{N="ToolsStatus";E={$_.ExtensionData.Guest.ToolsStatus}}
}} | Export-Csv -NoTypeInformation -UseCulture -Path E:\scripts\VMsInfo.csv
or, to cut a couple of lines, you could pass the VM names directly to Get-VM, since the names are not used elsewhere in the script. That would look like:
(Get-VM "vm1", "vm2", "vm3" | Select-Object -Property Name,
@{N="DNS Name";E={$_.ExtensionData.Guest.HostName}},
PowerState,numCPU,MemoryMB,Version,
Id,ProvisionedSpaceGB,UsedSpaceGB,VMHost,
@{N="ToolsVersion";E={$_.ExtensionData.Config.Tools.ToolsVersion}},
@{N="ToolsStatus";E={$_.ExtensionData.Guest.ToolsStatus}}
) | Export-Csv -NoTypeInformation -UseCulture -Path E:\scripts\VMsInfo.csv
Both ways should result in a single CSV file with one row of header info and three (3) rows of VM info. You said, "no headers", but I took that to mean that you did not want a header row for each VM's info, not that you wanted no headers whatsoever.
Enjoy