4 Replies Latest reply on Nov 14, 2019 5:11 AM by ganapa2000

    Unable to get connect vcenter name

    ganapa2000 Hot Shot

      Hi,

       

      I am trying to get connect vCenter name from the below script, vcenter name shows blank in the output

       

      Connect-viserver -Server (Get-Content .\DEMO_VC.txt) > $null

      $VmInfo = Foreach($vc in $global:DefaultVIServers){

      ForEach ($VM in Get-Folder Dev | Get-VM)

      {

      ($VM.Extensiondata.Guest.Disk | Select @{N="Name";E={$VM.Name}},

      @{N="vCenter";E={$VM_.Uid.Split('@')[1].Split(':')[0]}},

      @{N="IPAddress";E={$VM.guest.IPAddress[0]}},

      @{N="VM PowerState";E={@($VM.PowerState)}},

      @{N="Operating System"; E={@($VM.guest.OSFullName)}},

      @{N="Folder";E={$VM.Folder.Name}}

      }

      }

      $VmInfo

       

      Please help..

        • 1. Re: Unable to get connect vcenter name
          LucD Guru
          User ModeratorsCommunity WarriorsvExpert

          Try with

           

          @{N = 'vCenter'; E = { ([uri]$vm.ExtensionData.Client.ServiceUrl).Host } }

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: Unable to get connect vcenter name
            ganapa2000 Hot Shot

            LucD,

             

            That worked, but I am getting the VM names twice from both vcenter. how can I avoid getting duplicates

            • 3. Re: Unable to get connect vcenter name
              LucD Guru
              Community WarriorsvExpertUser Moderators

              Are your vCenters in linked mode?
              You can use the Server parameter, like this

               

              Connect-viserver -Server (Get-Content .\DEMO_VC.txt) > $null

               

              $VmInfo = Foreach ($vc in $global:DefaultVIServers) {

                  ForEach ($VM in (Get-Folder -Name Dev -Server $vc | Get-VM -Server $vc)) {

                      $VM.Extensiondata.Guest.Disk | Select @{N = "Name"; E = { $VM.Name } },

                          @{N = 'vCenter'; E = { ([uri]$vm.ExtensionData.Client.ServiceUrl).Host } }

                          @{N = "IPAddress"; E = { $VM.guest.IPAddress[0] } },

                          @{N = "VM PowerState"; E = { @($VM.PowerState) } },

                          @{N = "Operating System"; E = { @($VM.guest.OSFullName) } },

                          @{N = "Folder"; E = { $VM.Folder.Name } }

                      }

                  }

              $VmInfo

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 4. Re: Unable to get connect vcenter name
                ganapa2000 Hot Shot

                perfect....that worked

                 

                Thank you very much!!!