0

I rung the following command inside powercli 5.5:-

PowerCLI C:\> Connect-VIServer -Server  172.16.20.101 -User root -Password ****

but I got a dialog to enter username and password although I am supplying the username & password in the script -User & -Password? so can anyone advice why powercli is not recognizing these parameters ?

John John
  • 339
  • 1
  • 4
  • 12

1 Answers1

1

I believe the User and Password parameters have been deprecated in the newest versions of PowerCLI. Use -Credential with a pscredential object instead:

$Username = 'root'
$Password = 'Sup4hS3cuRe' | ConvertTo-SecureString -AsPlainText -Force
$Credential = New-Object -TypeName pscredential -ArgumentList $Username,$Password

Connect-VIServer -Server 172.16.20.101 -Credential $Credential
Mathias R. Jessen
  • 24,907
  • 4
  • 62
  • 95
  • not sure how did it work but I just surrounded the password with " " and I can connect without being prompted with a dialog ... – John John Aug 05 '15 at 12:05
  • @JohnJohn Cool, if that's your solution, add an answer yourself :) – Mathias R. Jessen Aug 05 '15 at 12:21
  • I think your script is better and more secure, but when I run your script I got the following error :- New-Object : Cannot find type [pscredential]: make sure the assembly containing this type is loaded. At line:1 char:25 + $Credential = New-Object <<<< -TypeName pscredential -ArgumentList $Username ,$Password + CategoryInfo : InvalidType: (:) [New-Object], PSArgumentExcepti on + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewOb jectCommand – John John Aug 05 '15 at 13:06
  • @Mathiase I am using power shell 5.5 release 1. can you advice on this please? – John John Aug 05 '15 at 13:06
  • @JohnJohn try substituting `pscredential` with the full type name `System.Management.Automation.PSCredential` – Mathias R. Jessen Aug 05 '15 at 13:14