TheVMinator
Expert
Expert

Running a PowerCLI script against multiple vCenters at the same time

Jump to solution

Can I run a powerCLI script against more than one vCenter simultaneously?

For example:

get-vm

and have it report all VMs in two different vCenters?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

First, a clarification, connecting, with AllLinked set to $true, to a vCenter that is part of a vCenter Server federation, is not the same as running PowerCLI in Multiple mode.

In Multiple mode all vSphere Server connections that are made, are stored together in the $global:defaultVIServers variable.

All cmdlets, that do no specify a specific vSphere Server with the Server parameter, will be executed to all vSphere servers in the $global:defaultVIServers variable.

For your issue, let's first check if all is configured correctly.

Check if the configuration is saying "Multiple" for all the scopes.

Get-PowerCLIConfiguration

If you see something like this

multiple.png

the setting will only be for your current session.

When you stop/start the session, the setting will be gone.

You can change the setting for AllUsers, like this

Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -Scope AllUsers

Then you will see this

multiple.png

and the configuration will be remembered between sessions.


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

View solution in original post

0 Kudos
8 Replies
LucD
Leadership
Leadership

Yes, you will have to switch to "multiple" mode first.

You can do this with the Set-PowerCLIConfiguration cmdlet and the DefaultVIServerMode switch.

Then you connect to all the vSphere servers you need to use. You can check by displaying the following variable

$global:defaultVIServers

Your script will now run against all the connected servers,

An alternative is to connect all your vCenters in linked mode.


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

rtunisi
Contributor
Contributor

just to complete Luc post: when connecting to LinkedMode vCenters, use the '-AllLinked' parameter on Connect-VIServer

0 Kudos
TheVMinator
Expert
Expert

Ok thanks for the info.  I'm still having an issue though:

I ran

set-powercliconfiguration -defaultviservermode multiple

I connected to one vcenter

Then I connected to another vcenter

But when I display the

$global:defaultVIServers

variable it still only shows one of the vcenters

Any ideas why is it not showing both vCenters?

0 Kudos
LucD
Leadership
Leadership

First, a clarification, connecting, with AllLinked set to $true, to a vCenter that is part of a vCenter Server federation, is not the same as running PowerCLI in Multiple mode.

In Multiple mode all vSphere Server connections that are made, are stored together in the $global:defaultVIServers variable.

All cmdlets, that do no specify a specific vSphere Server with the Server parameter, will be executed to all vSphere servers in the $global:defaultVIServers variable.

For your issue, let's first check if all is configured correctly.

Check if the configuration is saying "Multiple" for all the scopes.

Get-PowerCLIConfiguration

If you see something like this

multiple.png

the setting will only be for your current session.

When you stop/start the session, the setting will be gone.

You can change the setting for AllUsers, like this

Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -Scope AllUsers

Then you will see this

multiple.png

and the configuration will be remembered between sessions.


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

View solution in original post

0 Kudos
TheVMinator
Expert
Expert

em32> Get-PowerCLIConfiguration

It was set to multiple for "all users" but not for "user".  I ran

Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -Scope User


and that resolved it - thanks!

0 Kudos
sureshsiwach
Contributor
Contributor

Hi LucD,

I was also facing the same problem and use the method provided by you. But when I have tested it it was not working then I have open new session of power CLI then its stared working.

Note:- Please open a new session after changing your configuration so you get desired output.

Thanks

Suresh Siwach

Thanks Suresh Siwach If you found this answer useful then mark it as correct and helpful.
0 Kudos
LucD
Leadership
Leadership

Note that you can also change that setting in the "session" scope, that way you shouldn't have to restart your session.


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

0 Kudos
AmolPatil
Enthusiast
Enthusiast

So finally how you did this simultaneously to connect all the VC.

I also trying to do the same but no luck.

I want to get Multiple VM's information from multiple VCs, but currently I am pushing this using Foreach loop to get inside VC's details.

I want to run my script parallelly on all mentioned VCs.

LucD assist me to use Job but didn't understand so looking for some example to get this done.

Your help appreciated.

Regards, Amol Patil VCP 5
0 Kudos