Wednesday, March 14, 2012

PowerCLI - Formatted table of VM's and their corresponding hosts

Connect-VIServer 192.168.10.196 -User administrator -Password XXXXXX

"{0,-30}           {1,-20}" -f "VM","Host"
"{0,-30}           {1,-20}" -f "--","----"
Get-VM | %{
    $vmHost = $_.VMHost
    foreach($hst in $vmHost) {
         "{0,-30}           {1,-20}" -f "$_","$hst"
    }
}

Output:
VM                                       Host                
--                                       ----                
w2k8_vcenter_1                           192.168.10.1         
NTNX-Ctrl-VM-1-perses                    192.168.10.1         
NTNX_vMA                                 192.168.10.1         
laura-ubuntu                             192.168.10.1         
NTNX-Ctrl-VM-2-perses                    192.168.10.2         
NTNX-Ctrl-VM-3-perses                    192.168.10.3 

No comments:

Post a Comment