VMware Cloud Community
patchste
Contributor
Contributor
Jump to solution

add-vmhost issue

Hi All

I am testing out VMWare PowerCli 5.5 release 1.  I have a lab with the following:

1 x VCenter Server Appliance 5.5

3 x ESX 5.5 hosts

I am trying to add the ESX hosts to VCenter with PowerCli.

I have successfully added the 1st host with the following

add-vmhost -Server 192.168.199.201 -Name ESX1 -Location (Get-Datacenter -Name LAB) -User root -Password password -force

I am trying to add the next hosts without the -User parameter and instead use the -Credential.

I have added the following to PowerCli .

New-VICredentialStoreItem -Host 192.168.199.203 -User root -Password password -File "C:\LAB\lab.xml"

add-vmhost -Server 192.168.199.203 -Name ESX3 -Location (Get-Datacenter -Name LAB) -credential (Get-VICredentialStoreItem -host 192.168.199.203 -File C:\lab\lab.xml)

It failed with the below error

Add-VMHost : Cannot bind parameter 'Credential'. Cannot convert the "VMware.Vim

Automation.ViCore.Cmdlets.Commands.Framework.VICredentialStoreItemImpl" value o

f type "VMware.VimAutomation.ViCore.Cmdlets.Commands.Framework.VICredentialStor

eItemImpl" to type "System.Management.Automation.PSCredential".

At line:1 char:95

+ add-vmhost -Server 192.168.199.203 -Name ESX3 -Location (Get-Datacenter -Name

LAB) -credential <<<<  (Get-VICredentialStoreItem -host 192.168.199.203 -File

C:\lab\lab.xml)

    + CategoryInfo          : InvalidArgument: (:) [Add-VMHost], ParameterBind

   ingException

    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomat

   ion.ViCore.Cmdlets.Commands.AddVMHost

Can anyone advise on why it is not working and how best to get the syntax


Thanks


Steve


1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The VICredentialStoreItem is not intended to be passed on the Credential parameter.

That parameter expects a PSCredential (which you can create with a Get-Credential cmdlet).

The New-VICredentialStoreItem is linked to a specific vSphere host with the Host parameter.

The idea is that you do not specify any credentials when you connect to that vSphere server.

PowerCLI will find the stored item based on the Host parameter in the VICredential store.


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

View solution in original post

Reply
0 Kudos
3 Replies
markdjones82
Expert
Expert
Jump to solution

I haven't used the VICredentialstore, but I believe that is only used when trying to connect-viserver it will pass those credentials, but someone correct me if wrong.

That being said, I believe you need to pass a PScredential type.

Try the code from this article:

PowerShell - How to create a PSCredential object - Kotesh Bandhamravuri - Site Home - MSDN Blogs

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com
LucD
Leadership
Leadership
Jump to solution

The VICredentialStoreItem is not intended to be passed on the Credential parameter.

That parameter expects a PSCredential (which you can create with a Get-Credential cmdlet).

The New-VICredentialStoreItem is linked to a specific vSphere host with the Host parameter.

The idea is that you do not specify any credentials when you connect to that vSphere server.

PowerCLI will find the stored item based on the Host parameter in the VICredential store.


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

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

The Add-VMHost -Credential cmdlet expects a value of type PSCredential. The Get-VICredentialStoreItem cmdlet returns a VICredentialStoreItemImpl object. These two don't match.

You can use:

PowerCLI C:\> New-VICredentialStoreItem -Host 192.168.199.203 -User root -Password password -File "C:\LAB\lab.xml"

PowerCLI C:\> $Credential = Get-VICredentialStoreItem -host 192.168.199.203 -File C:\LAB\lab.xml

PowerCLI C:\> add-vmhost -Server 192.168.199.203 -Name ESX3 -Location (Get-Datacenter -Name LAB) -User $Credential.User -Password $Credential.Password

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition