PowerCLI

 View Only
  • 1.  PowerCLI Script to list VMs by their hosts

    Posted Sep 17, 2013 02:57 AM

    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?



  • 2.  RE: PowerCLI Script to list VMs by their hosts
    Best Answer

    Posted Sep 17, 2013 03:13 AM

    Hello, -

    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?



  • 3.  RE: PowerCLI Script to list VMs by their hosts

    Posted Sep 17, 2013 03:37 AM

    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.