VMware Cloud Community
chakoe
Enthusiast
Enthusiast

Build filter for Get-View

Hi,

in a Script i am using the following line:

Get-View -ViewType ClusterComputeResource -Property Name, Host | Select Name, Host | Sort-Object Name

Because we have 3 Virtual-Datacenters in our VirtualCenter, the cmdlet gets all Clusters in all Datacenters.

( DC1,DC2,DC3)

I would like to get only the clusters of DC1

What do i have to change? Do i have to set a filter?

Thx in advance

Chakoe

0 Kudos
2 Replies
RvdNieuwendijk
Leadership
Leadership

You will have to use a filter. But I could not find a fast solution. It is much easier with other PowerCLI cmdlets:

Get-Datacenter DC1 |
Get-Cluster |
Select-Object -Property Name,@{N="Host";E={$_.ExtensionData.Host}} |
Sort-Object -Property Name

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
mattboren
Expert
Expert

Hello, chakoe-

As Robert showed, you can use other PowerCLI cmdlets to help narrow the search.

Another way, if you wanted to stick (or needed to) with Get-View, would be to use the -SearchRoot parameter to set the root inventory spot in which to base the search.  Something like:

Get-View -ViewType ClusterComputeResource -SearchRoot (Get-Datacenter DC1).Id -Property Name, Host | Select Name, Host | Sort-Object Name

The -SearchRoot param expects a MoRef of the inventory object that you intend to use as the root.

How does that do for you?