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
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
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
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?
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}}
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
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}}
It depends what you have in that .txt file?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
its just a list of esxhosts
host1
host2
host3
the command take a long time to run though
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