VMware Cloud Community
tdubb123
Expert
Expert
Jump to solution

get-view -viewtype

can i use get-view -viewtype to filter on multiple items?

ex

I want to get esxi version of esxi hosts on cluster1

get-view -viewtype computeresource -filter @{"Name"="cluster1"}

but how do I get the esxi hosts as well?

get-view -viewtype hostsystem -filter

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

No need to use the Filter in this case, you can use the SearchRoot parameter.

Something like this

$clusterName = 'MyCluster'

$cluster = Get-Cluster -Name $clusterName

Get-View -ViewType HostSystem -Property Name,Config.Product -SearchRoot $cluster.ExtensionData.MoRef |

Select Name,@{N='Version';E={$_.Config.Product.Version}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
8 Replies
LucD
Leadership
Leadership
Jump to solution

No need to use the Filter in this case, you can use the SearchRoot parameter.

Something like this

$clusterName = 'MyCluster'

$cluster = Get-Cluster -Name $clusterName

Get-View -ViewType HostSystem -Property Name,Config.Product -SearchRoot $cluster.ExtensionData.MoRef |

Select Name,@{N='Version';E={$_.Config.Product.Version}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
tdubb123
Expert
Expert
Jump to solution

thanks Luc

how about if I got a text file of hosts instead

is this the best way to get the data

$vmhosts = get-content vmhosts.txt

foreach ($vmhost in $vmhosts){

get-vmhost | get-view | select Name, @{N="version";e={$_.extensiondata.config.product.version}

or can i still use get-view -viewtype?

Reply
0 Kudos
tdubb123
Expert
Expert
Jump to solution

ok i think this worked as well

get-view -viewtype hostsystem -SearchRoot (get-content .\vmhosts.txt).Id | select NAme, @{N="version";e={$_.config.product.fullname}}

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'm afraid that would not work, the SearchRoot parameter expects a MoRef.

In this case you better use the Filter.

Join the names together with the RegEx Or operator.

Something like this

$esxNames = (Get-Content .\vmhosts.txt) -join '|'

Get-View -ViewType HostSystem -Filter @{'Name'=$esxNames} |

select Name, @{N="Version";e={$_.config.product.fullname}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
tdubb123
Expert
Expert
Jump to solution

lucd

i tried this command and it is working.

can you try ?

get-view -viewtype hostsystem -SearchRoot (get-content .\vmhosts.txt).Id | select NAme, @{N="version";e={$_.config.product.fullname}}

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

It depends what you have in that .txt file?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
tdubb123
Expert
Expert
Jump to solution

its just a list of esxhosts

host1

host2

host3

the command take a long time to run though

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I suspect that might return something because the cmdlet seems to interpret that as a $null value for the SearchRoot parameter.

In fact when I do the following, it returns indeed all ESXi nodes under my vCenter.

I suspect it might also returns all ESXi nodes known under your vCenter, independent what you put in the .txt file.

Get-View -ViewType HostSystem -SearchRoot $null | select Name


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos