7 Replies Latest reply on Sep 19, 2012 6:10 AM by DrewK201110141

    Determine vCenter managing host

    DrewK201110141 Lurker

      Is there a way with PowerCLI / PowerShell to query a host and have it return the IP (or name) of the vCenter that is manageing that host?.

       

      vCenter version 5.0

      ESX(i) version 5.0

      PowerCLI  version 5

       

      Thanks,

       

      Drew

        • 1. Re: Determine vCenter managing host
          Grzesiekk Expert

          Hi there,

          i belive you can do it with:

           

          (get-vmhost  yourhost.local).uid.Split(":")[0].Split("@")[1]

           

          as per

          http://www.lucd.info/viproperties/

          • 2. Re: Determine vCenter managing host
            jade_ Novice

            I use a method like this from the View data:

            PowerCLI C:\> $hh= get-view -viewtype hostsystem -property name |select -first 1
            PowerCLI C:\> $hh.Client
            Version          : Vim41
            VimService       : VimApi_41.VimService
            ServiceContent   : VMware.Vim.ServiceContent
            ServiceUrl       : https://VC-SERVER1:443/sdk
            ServiceTimeout   : 100000
            CertificateError : System.EventHandler`1[VMware.Vim.CertificateErrorEventArg]

             

            You can play with the return substring for the length of the section you want like:

             

             

            $hh.Client.ServiceUrl.Substring(8,13)

             

             

            Thanks!

             

            Jade

            • 3. Re: Determine vCenter managing host
              DrewK201110141 Lurker

              Thanks for the responses, but these are both giving me the host I'm connected to and not the name of the vCenter server.  When I connect to the host with the vSphere client I get a message like this

               

              9-18-2012 16-15-11.jpg

               

              It's the address covered in purple I'm trying to get.

               

              Thanks,

               

              DK

              • 4. Re: Determine vCenter managing host
                jade_ Novice

                Are you unable to see it when you point the VI CLient to the address in purple?    From the screenshot; it looks like you are connecting direcly to the ESXi node with the GUI.    Both the examples assume that you are connected to the VC server.  While there are ways to tell in the VPX configs on the ESXi host; but its worth noting that the popup has the answer to the question posed.

                 

                Alternatly; you could connect-viserver and issue a get-vmhost to list the node you are looking for.

                 

                HTH!

                 

                Thanks

                 

                Jade

                • 5. Re: Determine vCenter managing host
                  mattboren Master
                  vExpert

                  Hello, DrewK201110141-

                   

                  I believe that you are looking for the ManagementServerIp property of the ESXi host object.  Per the API reference at that hyperlink, this property contains the "IP address of the VirtualCenter server managing this host, if any".  A couple of the other answers here were directing you towards the server to which you connected with your PowerCLI session, but you want the vCenter server that is currently managing the given host (if any), it seems.  If so, you should be able to get that like:

                   

                  ## get the management server IP info (if any) hostsystems
                  Get-View -ViewType HostSystem -Property Name,Summary.ManagementServerIp | Select Name, @{n="MgmtVCenterIP"; e={$_.Summary.ManagementServerIP}}

                   

                  The output should be something like:

                   

                  Name        MgmtVCenterIP
                  ----        -------------
                  myESXiHost  192.0.0.31   
                  

                   

                  If you are connected to a vCenter server, that should return said info for all HostSystems in that vCenter's inventory.  Or, if you are connected directly to a host, it will just return that one host's info.  How does that do?

                  • 6. Re: Determine vCenter managing host
                    Grzesiekk Expert

                    Hi Matt,

                      just curious if there is any reason why this might not be working ?

                    $c=get-view -id HostSystem-host-777
                    $c.summary


                    Host               : HostSystem-host-777
                    Hardware           : VMware.Vim.HostHardwareSummary
                    Runtime            : VMware.Vim.HostRuntimeInfo
                    Config             : VMware.Vim.HostConfigSummary
                    QuickStats         : VMware.Vim.HostListSummaryQuickStats
                    ManagementServerIp :

                     

                     

                    ManagementServerIP is empty.

                     

                     

                    @update.

                     

                    Now i know why it is empty

                    When i will connect with powercli directly to vmhost and not to VC, this managementServerIP will be displayed. When connecting to the VC this property is not populated.

                     

                     

                    • 7. Re: Determine vCenter managing host
                      DrewK201110141 Lurker

                      I'm building a configuration script for all of our host and I want to determine what virtual center this box is managed by as part of the script and use it as a condition.

                       

                      Thanks,

                       

                      DK