If you need the view of the VM to get some advanced information you can do it slightly quicker using the following outline. There is no need for it in this case, but I wanted to provide something similar to what has been done.
$report = @()
foreach ($vmView in (Get-View -ViewType VirtualMachine))
{
$report += $vmView | Select-Object @{Name="VMHost"; Expression={(Get-View $vmView.Runtime.Host).Name}},
@{Name="VMName"; Expression={$_.Name}},
@{Name="GuestVersion"; Expression={$vmView.Guest.GuestFullName}}
}
$report | Sort-Object VMName -Descending | Export-Csv "C:\vm_GuestVersion.csv" -NoTypeInformation