VMware Cloud Community
f10
Expert
Expert

"New-VICredentialStoreItem" for all ESXi hosts managed by the same vCenter

Hi Folks,

I am trying to encrypt the password for the ESXi hosts in a script that I am going to run against all the ESXi host in the vCenter, thankfully all the ESXi hosts though spread across multiple clusters have the same username and password. I felt using the "New-VICredentialStoreItem" would be easy but it seems that this option does not work for all ESXi hosts in the same command.

I have around 50 ESXi hosts all with the same password, can someone please suggest the most easiest and convenient way to achieve this. 

Here is the snip of the commands that i was trying, it works perfectly for the vCenter server but not for all the ESxi hosts.

PowerCLI C:\script> Connect-VIServer -Server 10.110.X.X

Name                           Port  User

----                           ----  ----

10.110.X.X                   443   administrator@vsphere.local

PowerCLI C:\script> $esxilist = get-vmhost

PowerCLI C:\script> New-VICredentialStoreItem -Host $esxilist -User root -Passwo

rd vmware@123

New-VICredentialStoreItem : Cannot convert 'System.Object[]' to the type 'Syste

m.String' required by parameter 'Host'. Specified method is not supported.

At line:1 char:32

+ New-VICredentialStoreItem -Host <<<<  $esxilist -User root -Password vmware@1

23

    + CategoryInfo          : InvalidArgument: (:) [New-VICredentialStoreItem]

   , ParameterBindingException

    + FullyQualifiedErrorId : CannotConvertArgument,VMware.VimAutomation.ViCor

   e.Cmdlets.Commands.NewVICredentialStoreItem

Thanks in advance.

Regards, Arun Pandey VCP 3,4,5 | VCAP-DCA | NCDA | HPUX-CSA | http://highoncloud.blogspot.in/ If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
0 Kudos
2 Replies
sneddo
Hot Shot
Hot Shot

Try this:

Connect-VIServer -Server 10.110.X.X

get-vmhost | %{ New-VICredentialStoreItem -Host $_ -User root -Password vmware@123 }


Basically, you are passing an array of hosts, where New-VICredentialStoreItem expects a single host. This just loops over the array and runs New-VICredentialStoreItem on each host.

0 Kudos
LucD
Leadership
Leadership

Your issue comes from the fact that your Get-VMHost returns more than 1 ESXi server.

And the Host parameter on New-VICredentialStoreItem expects a single hostname as a string


You can do

Get-VMHost | %{

    New-VICredentialStoreItem -Host $_.Name -User root -Password 'vmware@123'

}


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

0 Kudos