Hi,
I am having difficulty in validating the vcenter server.
I have saved the credentials using New-VICredentialStoreItem, if the vcenter service is up, it connects without any issue else below script is prompting for username and password again.
how can I exist the script, when there is a issue with vcenter
Please help.
$array = @()
Try {
connect-viserver 10.10.10.10 -ErrorAction Stop | Out-Null
get-vm
}
Catch {
write-host "Not able to connect to vCenter"
return
}
$array
That is due to the order in which Connect-VIServer checks the parameters.
It will 1st try to get the credentials.
You can first test if the VCSA is reachable, before trying the COnnect-VIServer.
Something like this
if(Test-NetConnection -ComputerName $vcName -Port 443 -InformationLevel Quiet -WarningAction SilentlyContinue){
Connect-VIServer -Server $vcName
Get-VM
}
else{
Write-Host "Not able to connect to vCenter"
return
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
At the backend, I am seeing below error
Connect-VIServer : 28-11-2019 17:34:30 Connect-VIServer
The HTTP service located at https://10.10.10.10/sdk is unavailable.
But the script is still prompting for username and password.
I would like to end the script, if something like this happens.
Can you also try with -Port 9443?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference