Automation

 View Only
Expand all | Collapse all

Command to tell what vCenter you are connected to

MikeF2691

MikeF2691Jun 25, 2019 02:26 PM

  • 1.  Command to tell what vCenter you are connected to

    Posted Nov 17, 2017 03:35 PM

    Is there a PowerCLI command to display which vCenter(s) you are connected to?



  • 2.  RE: Command to tell what vCenter you are connected to

    Posted Nov 17, 2017 04:58 PM

    One way is

    ([System.Uri]$global:defaultviserver.Client.Config.ServiceUrl).Host



  • 3.  RE: Command to tell what vCenter you are connected to

    Posted Nov 17, 2017 05:14 PM

    I get no output when I enter that command. No error or anything, just returns me back to C:\ prompt



  • 4.  RE: Command to tell what vCenter you are connected to
    Best Answer

    Posted Nov 17, 2017 05:16 PM

    You are connected?

    Display what is in $global:defaultviserver



  • 5.  RE: Command to tell what vCenter you are connected to

    Posted Nov 17, 2017 05:18 PM

    Yes I am.

    This command works!

    $global:defaultviserver



  • 6.  RE: Command to tell what vCenter you are connected to

    Posted Nov 17, 2017 05:27 PM

    And does this contain the Uri to the vCenter?

    $global:defaultviserver.Client.Config.ServiceUrl

    Btw, which PowerCLI version are you using?

    Do a Get-PowerCLIVersion



  • 7.  RE: Command to tell what vCenter you are connected to

    Posted Nov 17, 2017 05:30 PM

    PowerCLI C:\> Get-PowerCLIVersion

    PowerCLI Version

    ----------------

       VMware PowerCLI 6.5 Release 1 build 4624819

    ---------------

    Component Versions

    ---------------

       VMware Cis Core PowerCLI Component 6.5 build 4624453

       VMware VimAutomation Core PowerCLI Component 6.5 build 4624450

       VMWare ImageBuilder PowerCLI Component 6.5 build 4561891

       VMWare AutoDeploy PowerCLI Component 6.5 build 4561891

       VMware Vds PowerCLI Component 6.5 build 4624695

       VMware Cloud PowerCLI Component 6.5 build 4624821

       VMware HA PowerCLI Component 6.0 build 4525225

       VMware HorizonView PowerCLI Component 7.0.2 build 4596620

       VMware Licensing PowerCLI Component 6.5 build 4624822

       VMware PCloud PowerCLI Component 6.5 build 4624825

       VMware Storage PowerCLI Component 6.5 build 4624820

       VMware vROps PowerCLI Component 6.5 build 4624824

       VMware vSphere Update Manager PowerCLI 6.5 build 4540462



  • 8.  RE: Command to tell what vCenter you are connected to

    Posted Nov 17, 2017 05:40 PM

    And do you see the Uri of the vCenter?



  • 9.  RE: Command to tell what vCenter you are connected to

    Posted Nov 17, 2017 05:41 PM

    This is what I get

    PowerCLI C:\>

    PowerCLI C:\>

    PowerCLI C:\> $global:defaultviserver.Client.Config.ServiceUrl

    PowerCLI C:\>



  • 10.  RE: Command to tell what vCenter you are connected to

    Posted Nov 17, 2017 05:45 PM

    Strange, and what about this variation?

    ([System.Uri]$global:defaultviserver.ServiceUri.AbsoluteUri).Host



  • 11.  RE: Command to tell what vCenter you are connected to

    Posted Nov 17, 2017 05:46 PM

    That works!

    Is there a newer version of PowerCLI out? What are you running?



  • 12.  RE: Command to tell what vCenter you are connected to

    Posted Nov 17, 2017 06:04 PM

    Since a couple of hours ago, there is PowerCLI 6.5.4.

    But you will have to install it from the PowerShell Gallery with Install-Module, no MSI file anymore.

    See Welcome PowerCLI to the PowerShell Gallery – Install Process Updates



  • 13.  RE: Command to tell what vCenter you are connected to

    Posted Feb 05, 2020 03:00 PM

    @LucD This solution worked for me, making this first post to post this reply and just say man thanks for your work in these forums you are all over the place and almost always on point in the solutions you are providing us.

    Thank you.



  • 14.  RE: Command to tell what vCenter you are connected to

    Posted Nov 15, 2018 09:38 AM
    $global:DefaultVIServers.Count - run this in powercli while you are connected to multiple VC. this will show names


  • 15.  RE: Command to tell what vCenter you are connected to

    Posted Nov 15, 2018 09:38 AM

    $global:DefaultVIServers.Name - run this in powercli while you are connected to multiple VC. this will show names



  • 16.  RE: Command to tell what vCenter you are connected to

    Posted Jun 25, 2019 02:26 PM
    This works, thanks


  • 17.  RE: Command to tell what vCenter you are connected to

    Posted Mar 04, 2021 06:36 PM

    I just want to put both of the correct answers in one post.

    • For 1 vCenter server, or the last vCenter server to which we connected, as  noted:
      $global:DefaultVIServer
    • For more than 1 vCenter server, as  noted,
      $global:DefaultVIServers

    A screenshot as an example:

    oz2edri_0-1614882972268.png