Trying to find a simple script that will output to a CSV a list of VMs and which host they currently are under but no luck so far. Closest I’ve found is Alan Renouf’s one below that lists the number of VMs per host but not the actual names.
Get-VMHost | Select @{N=“Cluster“;E={Get-Cluster -VMHost $_}}, Name, @{N=“NumVM“;E={($_ |Get-VM).Count}} | Sort Cluster, Name | Export-Csv -NoTypeInformation c:\clu-host-numvm.csv
Im sure it’s something along the simple lines of get-vmhost | get-vm but need the host listed. Any ideas?
Hello, Viewaskew-
There is a property, VMHost, of VM objects. So, you can just use a Get-VM call piped to a Select-Object statement (and then to Export-Csv), like:
Get-VM | Select Name,VMHost | Export-Csv -Path c:\temp\VMsAndHostsInfo.csv -NoTypeInformation -UseCulture
That do it for you?
Hello, Viewaskew-
There is a property, VMHost, of VM objects. So, you can just use a Get-VM call piped to a Select-Object statement (and then to Export-Csv), like:
Get-VM | Select Name,VMHost | Export-Csv -Path c:\temp\VMsAndHostsInfo.csv -NoTypeInformation -UseCulture
That do it for you?
Thanks Matt, that works perfectly. I was just going to post that I found: Get-VM | Select-Object Name,VMHost which did the trick as well but thank you for the complete one liner.