PowerCLI

 View Only
  • 1.  Connect to different vCenter

    Posted Apr 12, 2020 07:15 PM

    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
    }



  • 2.  RE: Connect to different vCenter
    Best Answer

    Posted Apr 12, 2020 07:27 PM

    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.

    # vCenter Login

    $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

    }



  • 3.  RE: Connect to different vCenter

    Posted Apr 12, 2020 07:29 PM

    Thank you LucD :smileyhappy:



  • 4.  RE: Connect to different vCenter

    Posted Apr 12, 2020 07:49 PM

    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



  • 5.  RE: Connect to different vCenter

    Posted Apr 12, 2020 07:54 PM

    The $global:defaultviserver and $global:defaultviservers are 2 automatic variables that get populated when you do a successful Connect-ViServer