Connecting to Multiple Virtual Centre Servers – Powercli

If you are working in an environment that has multiple Virtual center servers it can become tricky to manage them, the easiest way to pull data from your platform it to load them all into a command line and query the platforms all at once.

I use the below script in my lab and have on customer sites to connect  and run quick basic powercli checks across the whole platform e.g.

I have also found that this method is also really handy when running reports against all your infrastructure, you can use vRops for this but when you have separated vRops deployementsProd, Dev, Secure…. then you do not get a single view. I will be adding another post around firmware tracking in the future.

in the Set variables section add your username and the Virtual Centre Servers FQDN’s and away you go. It’s also advised that you create a disconnect script to kill off the sessions at the end of the day or run disconnect-viserver * -confirm:$false

Copy the below script into Notepad/Notpad++… edit the variables and save as a Connect-All-VC.ps1 you will then be able to run this in powercli ./Connect-All-VC.ps1 which will connect to all of your VC’s quickly and consistently.

#############################################################################################
#Set Variables###
$Username = '<YourUserName>'
##Enter your Virtual Centre servers you wish to connect to FQDN's######
#Prod#
$vc1 = 'prodvc01.somedomain.com' 
$vc2 = 'prodvc02.somedomain.com' 
$vc3 = 'prodvc03.somedomain.com' 
$vc4 = 'prodvc04.somedomain.com' 
#Dev# 
$vc5 = 'devprodvc01.somedomain.com' 
$vc6 = 'devprodvc02.somedomain.com' 
#MGMT# 
$vc7 = 'mgmtprodvc01.somedomain.com' 
$vc8 = 'mgmtprodvc02.somedomain.com' 
#Horizon#
$vc9 = 'HZ7prodvc01.somedomain.com' 
$vc10 ='HZ7prodvc02.somedomain.com' 
#############################################################################################
$credentials=Get-Credential -UserName $Username -Message "Enter your vCenter password"
#Connect
Write-Host "Connecting to Virtual Centre......" -ForegroundColor Green
connect-viserver -Server $vc1 -Credential $credentials 
connect-viserver -Server $vc2 -Credential $credentials
connect-viserver -Server $vc3 -Credential $credentials
connect-viserver -Server $vc4 -Credential $credentials
connect-viserver -Server $vc5 -Credential $credentials
connect-viserver -Server $vc6 -Credential $credentials
connect-viserver -Server $vc7 -Credential $credentials
connect-viserver -Server $vc8 -Credential $credentials
connect-viserver -Server $vc9 -Credential $credentials
connect-viserver -Server $vc10 -Credential $credentials

Example of running the script and seeing hosts from multiple VC’s.

Example Code
#############################################################################################
#Set Your Variables###
#Enter Your User Name
$Username = 'ssdom.com\administrator'
$credentials=Get-Credential -UserName $Username -Message "Enter your vCenter password"

##Enter your Virtual Centre FQDN's ####
#Prod#
$vc1 = 'vc01.ssdom.com' 
$vc2 = 'vc02.ssdom.com' 

#############################################################################################

#Connect## - Remove the lines that are not required
Write-Host "Connecting to Virtual Centre......" -ForegroundColor Green
connect-viserver -Server $vc1 -Credential $credentials 
connect-viserver -Server $vc2 -Credential $credentials