wreedMH
Hot Shot
Hot Shot

Command to tell what vCenter you are connected to

Jump to solution

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

1 Solution

Accepted Solutions
LucD
Leadership
Leadership

You are connected?

Display what is in $global:defaultviserver


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
16 Replies
LucD
Leadership
Leadership

One way is

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
wreedMH
Hot Shot
Hot Shot

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

0 Kudos
LucD
Leadership
Leadership

You are connected?

Display what is in $global:defaultviserver


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
wreedMH
Hot Shot
Hot Shot

Yes I am.

This command works!

$global:defaultviserver

0 Kudos
LucD
Leadership
Leadership

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
wreedMH
Hot Shot
Hot Shot

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

0 Kudos
LucD
Leadership
Leadership

And do you see the Uri of the vCenter?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
wreedMH
Hot Shot
Hot Shot

This is what I get

PowerCLI C:\>

PowerCLI C:\>

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

PowerCLI C:\>

0 Kudos
LucD
Leadership
Leadership

Strange, and what about this variation?

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
wreedMH
Hot Shot
Hot Shot

That works!

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

0 Kudos
LucD
Leadership
Leadership

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

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

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

MikeF2691
Contributor
Contributor
This works, thanks
0 Kudos
iLikePointyThni
Contributor
Contributor

@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.

0 Kudos
oz2edri
Contributor
Contributor

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 @LucD noted:
    $global:DefaultVIServer
  • For more than 1 vCenter server, as @Rohitekumarshar noted,
    $global:DefaultVIServers

A screenshot as an example:

oz2edri_0-1614882972268.png

 

0 Kudos