MatDesj
Contributor
Contributor

Get-Credential with -Message and Connect-VIServer

Jump to solution

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

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
MatDesj
Contributor
Contributor

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!

0 Kudos