3 Replies Latest reply on Nov 28, 2019 4:54 AM by LucD

    Validate vCenter server issue

    ganapa2000 Hot Shot

      Hi,

       

      I am having difficulty in validating the vcenter server.

       

      I have saved the credentials using New-VICredentialStoreItem, if the vcenter service is up, it connects without any issue else below script is prompting for username and password again.

       

      how can I exist the script, when there is a issue with vcenter

       

      Please help.

       

      $array = @()

        Try {

          connect-viserver 10.10.10.10 -ErrorAction Stop | Out-Null

          get-vm

        } 

        Catch {

        write-host "Not able to connect to vCenter"

        return 

        } 

      $array

        • 1. Re: Validate vCenter server issue
          LucD Guru
          vExpertCommunity WarriorsUser Moderators

          That is due to the order in which Connect-VIServer checks the parameters.

          It will 1st try to get the credentials.

           

          You can first test if the VCSA is reachable, before trying the COnnect-VIServer.

          Something like this

           

          $vcName = '10.10.10.10'

          if(Test-NetConnection -ComputerName $vcName -Port 443 -InformationLevel Quiet -WarningAction SilentlyContinue){

              Connect-VIServer -Server $vcName

              Get-VM

          }

          else{

              Write-Host "Not able to connect to vCenter"

              return  

          }

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: Validate vCenter server issue
            ganapa2000 Hot Shot

            LucD,

             

            At the backend, I am seeing below error

             

            Connect-VIServer : 28-11-2019 17:34:30  Connect-VIServer

            The HTTP service located at https://10.10.10.10/sdk is unavailable.

             

            But the script is still prompting for username and password.

             

            I would like to end the script, if something like this happens.

            • 3. Re: Validate vCenter server issue
              LucD Guru
              vExpertUser ModeratorsCommunity Warriors

              Can you also try with -Port 9443?

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz