1 Reply Latest reply on May 15, 2018 5:02 PM by xitanul

    get-view filter by vcenter and datacenter

    tdubb123 Master

      how do I combine get-view by both datacenter and virtualmachine?


      get-view -viewtype datacenter -filter {Name="DC1"}


      Get-View -ViewType VirtualMachine -filter {Name="test"}



        • 1. Re:get-view filter by vcenter and datacenter
          xitanul Lurker

          Try this:

          $Datacenter = Get-View -ViewType Datacenter -Filter @{Name="DC1"} -Property Name | Select-Object -ExpandProperty MoRef

          Get-View -ViewType VirtualMachine -Filter @{Name="test"} -Property Name -SearchRoot $Datacenter

          Or one-liner:

          Get-View -ViewType VirtualMachine -Filter @{Name="test"} -Property Name -SearchRoot $(Get-View -ViewType Datacenter -Filter @{Name="DC1"} -Property Name).MoRef


          ...Just make sure to add properties or remove the properties parameter altogether from the VirtualMachine Get-View to return all or specific property values.

          Specifying properties will greatly improve the query speed.


          $Datacenter = (Get-View -ViewType Datacenter -Filter @{Name="DC1"} -Property Name).MoRef


          Get-View -ViewType HostSystem -Filter @{Name="test"} -Property Name -SearchRoot $Datacenter