VMware PowerCLI

The Best User Interface for your VMware Datacenter!

Make Connect-VIServer fail with error when passthrough authenticaion fails

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:


This first example works like expected

$vCenterName = "vc.yourdomain.com"

$creds = Get-Credential -Prompt "Please enter login credentials for vCenter: $vCenterName"

Connect-VIServer -Server $vCenterName -Credential:$creds -ErrorAction:Stop


This second example does not throw an error

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.









  • Guest
  • Oct 25 2022
  • Looking for Feedback
  • Attach files
  • Admin
    Kamen Nikolov commented
    25 Oct 01:23pm

    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.