PowerCLI

 View Only
  • 1.  Get-Credential with -Message and Connect-VIServer

    Posted Mar 17, 2020 02:41 PM

    Hi everyone, I just want to validate a behavior that I experience here.

    I am using PowerCli version 11.3.0.13964826 and when trying to pass credential that way:

    $Cred = Get-Credential -Message "Try AA123456@test.com, Dev and QA AA123456"

    Connect-VIServer -Server  myserver  -user $Cred.Username -password $Cred.Password

    I get an error Cannot complete login due to an incorrect user name or password.

    But using that way:

    $Cred = Get-Credential

    Connect-VIServer -Server  myserver  -user $Cred.Username -password $Cred.Password

    I can connect without any error message.

    Any idea of what is not working here. And when I am showing the content of the variables, the content is the same in both case.

    Thank you!

    Mathieu



  • 2.  RE: Get-Credential with -Message and Connect-VIServer
    Best Answer

    Posted Mar 17, 2020 03:52 PM

    The Password property in the $Cred variable is a SecureString, while the -Password parameter on Connect-VIServer expects a string.

    There are 2 options

    • Use the Credential parameter

    $Cred = Get-Credential -Message "Try AA123456@test.com, Dev and QA AA123456"

    Connect-VIServer -Server  myserver -Credential $Cred

    • Convert the SecureString to a String

    $Cred = Get-Credential -Message "Try AA123456@test.com, Dev and QA AA123456"

    Connect-VIServer -Server  myserver -User $Cred.UserName -Password $Cred.GetNetworkCredential().Password



  • 3.  RE: Get-Credential with -Message and Connect-VIServer

    Posted Mar 17, 2020 05:10 PM

    Really strange because before adding the -Message I was using the same syntax to connect and it was working but indeed, using -Credential with Connect-VIServer seem to fix my issue.

    Thank you!