VMware Cloud Community
tdubb123
Expert
Expert
Jump to solution

get-vm with datacenter location column

how do I get VM info with datacenter location included in a column?

I check $_Extensiondata.config and did not se it under there

0 Kudos
1 Solution

Accepted Solutions
gcanales
Enthusiast
Enthusiast
Jump to solution

Try this:

Get-VM $vm | Format-table Name,

@{Name="Datacenter";Expression={$_.vmhost.parent.parentfolder.parent};a="center"} -a

Tested with a VM in a "clustered" host. I think it may change if host is not in a Cluster.

Hope it works

View solution in original post

0 Kudos
3 Replies
TScalzott
Enthusiast
Enthusiast
Jump to solution

This isn't the most elegant, but add it as a property with something like this:

$VMs = @()

Foreach ($cluster in (Get-Cluster)) {

   Foreach ($vm in (Get-VM)) {

      $vm | Add-Member -membertype NoteProperty -name Cluster -value $cluster.Name

      $VMs += $vm

      }

}

$VMs | Sort Cluster | Select-Object Cluster, Name

gcanales
Enthusiast
Enthusiast
Jump to solution

Try this:

Get-VM $vm | Format-table Name,

@{Name="Datacenter";Expression={$_.vmhost.parent.parentfolder.parent};a="center"} -a

Tested with a VM in a "clustered" host. I think it may change if host is not in a Cluster.

Hope it works

0 Kudos
tdubb123
Expert
Expert
Jump to solution

thank you for locating that object

0 Kudos