8 Replies Latest reply on Aug 14, 2017 9:10 AM by LucD

    get-view -viewtype

    tdubb123 Master

      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

        • 1. Re: get-view -viewtype
          LucD Guru
          vExpertCommunity WarriorsUser Moderators

          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}}

          • 2. Re: get-view -viewtype
            tdubb123 Master

            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?

            • 3. Re: get-view -viewtype
              tdubb123 Master

              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}}

              • 4. Re: get-view -viewtype
                LucD Guru
                Community WarriorsvExpertUser Moderators

                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}}

                • 5. Re: get-view -viewtype
                  tdubb123 Master

                  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}}

                  • 6. Re: get-view -viewtype
                    LucD Guru
                    Community WarriorsUser ModeratorsvExpert

                    It depends what you have in that .txt file?

                    • 7. Re: get-view -viewtype
                      tdubb123 Master

                      its just a list of esxhosts

                       

                      host1

                      host2

                      host3

                       

                      the command take a long time to run though

                      • 8. Re: get-view -viewtype
                        LucD Guru
                        vExpertCommunity WarriorsUser Moderators

                        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