VMware Cloud Community
wreedMH
Hot Shot
Hot Shot
Jump to solution

Command to tell what vCenter you are connected to

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

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You are connected?

Display what is in $global:defaultviserver


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

View solution in original post

Reply
0 Kudos
16 Replies
LucD
Leadership
Leadership
Jump to solution

One way is

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


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

Reply
0 Kudos
wreedMH
Hot Shot
Hot Shot
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You are connected?

Display what is in $global:defaultviserver


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

Reply
0 Kudos
wreedMH
Hot Shot
Hot Shot
Jump to solution

Yes I am.

This command works!

$global:defaultviserver

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
wreedMH
Hot Shot
Hot Shot
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

And do you see the Uri of the vCenter?


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

Reply
0 Kudos
wreedMH
Hot Shot
Hot Shot
Jump to solution

This is what I get

PowerCLI C:\>

PowerCLI C:\>

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

PowerCLI C:\>

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Strange, and what about this variation?

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


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

Reply
0 Kudos
wreedMH
Hot Shot
Hot Shot
Jump to solution

That works!

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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
Jump to solution

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

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

MikeF2691
Contributor
Contributor
Jump to solution

This works, thanks
Reply
0 Kudos
iLikePointyThni
Contributor
Contributor
Jump to solution

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

Reply
0 Kudos
oz2edri
Contributor
Contributor
Jump to solution

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

 

Reply
0 Kudos