I have a list of VCenter servers. They are on different locations and of different customers. I have created a text file with all the vcenter servers and credentials like below..I have more than 20 Vcenter Servers. I need to collect information of VM, Datastores, etc.(for which I have scripts).
Connect-VIServer vcenter0001 -User vcenter0001\sysdep -Password "Passwowrd1"
Connect-VIServer vcenter0002 -User vcenter0002\sysdep -Password "Passwowrd2"
I want to connect to each VCenter server and execute my scripts. Please help me. Thanks in Advance.
There's a couple ways to accomplish this, first you need to make sure that your configuration is set to allow for multiple connections. This is done with the following:
Set-PowerCLIConfiguration -DefaultVIServerMode Multiple
Note: It may also be necessary to run the following to enforce the change against all session scopes:
Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -Scope User
Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -Scope Session
Afterwards, you can pass multiple vCenter server names in string format or array format to the Connect-VIServer cmdlet to the 'Server' parameter.
Example using strings:
Connect-VIServer -Server vcenter0001,vcenter0002,vcenter0003 -User sysdep -Password "Password"
Example using an array:
$vCenterNames = @('vcenter0001','vcenter0002','vcenter0003')
Connect-VIServer -Server $vCenterNames -User sysdep -Password "Password"
Lastly, since it looks like you may be using local accounts instead of a single domain account, you could look at integrating the VICredentialStore. This saves your credentials in an XML file that will be referenced automatically at time of authentication.
Example Usage:
New-VICredentialStoreItem -Host vcenter0001 -User vcenter0001\sysdep -Password "Password"
New-VICredentialStoreItem -Host vcenter0002 -User vcenter0002\sysdep -Password "Password"
New-VICredentialStoreItem -Host vcenter0003 -User vcenter0003\sysdep -Password "Password"
Connect-VIServer -Server vcenter0001,vcenter0002,vcenter0003