Hello
I have created the below function in order to connect to some vcenters, unfortunatly like what I made it ask for crendiatial for each vcenter despite it's the same for All, so I need help to correct the function
Function ConnectTo-vCenter
{
foreach ($vCenter in $vCenterList){
Fonc_LOG "Connecting to $vCenter..."
$connection = Get-Credential -Message “Please enter your password”
If($? -Eq $True){
Fonc_LOG "Connected"
}
}
}
ConnectTo-vCenter
Inside the Foreach loop, something like this
{
$connection = Get-Credential -Message “Please enter your password”
foreach ($vCenter in $vCenterList){
Fonc_LOG "Connecting to $vCenter..."
Connect-VIServer -Server $vCenter -Credential $connection
If($? -Eq $True){
Fonc_LOG "Connected"
}
}
}
ConnectTo-vCenter
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You could move the Get-Credential outside of the Foreach loop.
Btw, the Connect-VIServer cmdlet is missing, I assume that is a typo.
{
$connection = Get-Credential -Message “Please enter your password”
foreach ($vCenter in $vCenterList){
Fonc_LOG "Connecting to $vCenter..."
If($? -Eq $True){
Fonc_LOG "Connected"
}
}
}
ConnectTo-vCenter
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
to be honest I missed it and it's working :smileyblush:
Connect-VIServer cmdlet is supposed to be placed where in the script?
Inside the Foreach loop, something like this
{
$connection = Get-Credential -Message “Please enter your password”
foreach ($vCenter in $vCenterList){
Fonc_LOG "Connecting to $vCenter..."
Connect-VIServer -Server $vCenter -Credential $connection
If($? -Eq $True){
Fonc_LOG "Connected"
}
}
}
ConnectTo-vCenter
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference