Would you please help me to understand how we can connect to different vcenter using PowerShell script?
I started with this lines, unfortunately each time I add a vcenter to this script it xonnect to last one on the list:
#Initialize PowerCLI
add-pssnapin VMware.VimAutomation.Core
# vCenter Login
$vCUser="domain\user"
$vCPass="Password"
# LIST OF vCenters
$vCenterIP = "x.x.x.x"
$vCenterIP = "x.x.x.x"
foreach ($IPAddress in $vCenterIP){
# Connessione a vCenter
Connect-VIServer $IPAddress -User $vCUser -Password $vCPass -port 443
}
You need to place the names in an array if you want to use a foreach loop like that.
Check what is in $global:defaultviservers after the foreach loop, it should show all your connected vCenters.
$vCUser="domain\user"
$vCPass="Password"
# LIST OF vCenters
$vCenterIP = "x.x.x.x","y.y.y.y","z.z.z.z"
foreach ($IPAddress in $vCenterIP){
# Connessione a vCenter
Connect-VIServer $IPAddress -User $vCUser -Password $vCPass -port 443
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You need to place the names in an array if you want to use a foreach loop like that.
Check what is in $global:defaultviservers after the foreach loop, it should show all your connected vCenters.
$vCUser="domain\user"
$vCPass="Password"
# LIST OF vCenters
$vCenterIP = "x.x.x.x","y.y.y.y","z.z.z.z"
foreach ($IPAddress in $vCenterIP){
# Connessione a vCenter
Connect-VIServer $IPAddress -User $vCUser -Password $vCPass -port 443
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you LucD
it's Ok now and I'm able to connect to 2 vCenter
but regarding $global:defaultviservers I don't have this variable in the script that I'm using.
I'm using the script that I find here Report_VirtualMachine.ps1
The $global:defaultviserver and $global:defaultviservers are 2 automatic variables that get populated when you do a successful Connect-ViServer
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference