Hi,
I find it very annoying that you cannot handle a connection failure if Passthrough authentication does not work.
Connect-VIServer will ALWAYS ask for credentials if it cannot connect to vCenter and you did not specify the credentials parameter. Even when using the -Force option.
This means that you need to either decide to skip the passthrough even when it is available, or accept that you cannot handle the Get-Credential yourself. In that case you will have to accept the default prompt without any explanation to the user.
Example Code:
$vCenterName = "vc.yourdomain.com"
$creds = Get-Credential -Prompt "Please enter login credentials for vCenter: $vCenterName"
Connect-VIServer -Server $vCenterName -Credential:$creds -ErrorAction:Stop
Preferably this code should NOT prompt for password when initial connection fails, but throw an error to let the programmer handle it.
$vCenterName = "vc.yourdomain.com"
Connect-VIServer -Server $vCenterName -ErrorAction:Stop
This should be an easy fix. Hope that someone else will support it.
I think that many people are using this prompt for the interactive use case where they just enter the name of the server and then enter the username and the password when prompted. But let's hear more opinions.