VMware Cloud Community
ewaud001
Contributor
Contributor
Jump to solution

Help with Get-View within a subset of clusters

I'm trying to do a get-view command that limits the results based on a subset of clusters. I can do this easily for VM objects but when I use the same type command for the view it does not work. Can someone suggest a working way to do this. Here is code that may better describe what I am doing:

\# Get VMs in subset of clusters ***this works

$Subset = "Cluster 2","Cluster 4","Cluster 6"

$VM = Get-Cluster $Subset | Get-VM | Sort Name

\# Get VM Views in subset of Clusters ***this does not work

$Subset = "Cluster 2","Cluster 4","Cluster 6"

$VMView = Get-Cluster $Subset | Get-View -ViewType VirtualMachine

Thanks in advance,

-Earl

0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Hi Earl,

The problem is that the Get-View cmdlet doesn't have the -Location parameter that is implicit used by the Get-VM cmdlet in the pipeline to filter on the clusters. You can change your code in the next way to get all the virtual machine views of the specified clusters:

$Subset = "Cluster2","Cluster 4","Cluster 6"
$VMView = Get-Cluster $Subset | Get-VM | Get-View

Regards, Robert

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

View solution in original post

0 Kudos
5 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Hi Earl,

The problem is that the Get-View cmdlet doesn't have the -Location parameter that is implicit used by the Get-VM cmdlet in the pipeline to filter on the clusters. You can change your code in the next way to get all the virtual machine views of the specified clusters:

$Subset = "Cluster2","Cluster 4","Cluster 6"
$VMView = Get-Cluster $Subset | Get-VM | Get-View

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
ewaud001
Contributor
Contributor
Jump to solution

(sorry. not sure what happened in the first post)

I'm trying to do a get-view command that limits the results based on a subset of clusters. I can do this easily for VM objects but when I use the same type command for the view it does not work. Can someone suggest a working way to do this. Here is code that may better describe what I am doing:

\# Get VMs in subset of clusters ***this works

$Subset = "Cluster 2","Cluster 4","Cluster 6"

$VM = Get-Cluster $Subset | Get-VM | Sort Name

\# Get VM Views in subset of Clusters ***this does not work

$Subset = "Cluster 2","Cluster 4","Cluster 6"

$VMView = Get-Cluster $Subset | Get-View -ViewType VirtualMachine

Thanks in advance,

-Earl

0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Hi Earl,

welcome to the VMware Communities.

If you are not happy with a post you can edit the post and change what you don't like.You don't have to make a new post ;-).

Did you see my post in between yours?

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
ewaud001
Contributor
Contributor
Jump to solution

Thanks Robert!

Your answer worked.

Regarding the edit/reply... my first post in this comment did not/does not offer an "edit" link. That is why I re posted the question as a reply. oddly, my re posted reply does have an edit link.

Anyway, thank you again for your swift and correct answer.

-Earl

0 Kudos
ewaud001
Contributor
Contributor
Jump to solution

Of course, now I see the edit thread link on the right side under action. Smiley Happy hehehe

0 Kudos