VMware Cloud Community
tdubb123
Expert
Expert

add-vmhost

I am trying to add 2 vmhost back into a clusterbut getting an error

$cluster = get-cluster -name "WDC"

$strcomputers = @("host1", "host2"}

add-vmhost -name $strcomputers -location $cluster -user root -password "xxxxxxxxxx" -confirm:$false

Add-VMHost : Cannot convert 'System.Object[]' to the type 'System.String'

required by parameter 'Name'. Specified method is not supported.

At line:1 char:18

+ Add-VMHost -Name $strcomputers -Location $cluster -User root -Password

"xxxxxxxxxxxx ...

+                  ~~~~~~~~~~~~~

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

   ingException

    + FullyQualifiedErrorId : CannotConvertArgument,VMware.VimAutomation.ViCor

   e.Cmdlets.Commands.AddVMHost

any idea?

0 Kudos
3 Replies
kunaludapi
Expert
Expert

$cluster = get-cluster -name "WDC"

$strcomputers = "host1", "host2"

$strcomputers | foreach {add-vmhost -name $_ -location $cluster -user root -password "xxxxxxxxxx" -confirm:$false}

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
0 Kudos
tdubb123
Expert
Expert

thank you. just wondering why this line does not work

add-vmhost -name $strcomputers -location $cluster -user root -password "xxxxxxxxxx" -confirm:$false

0 Kudos
LucD
Leadership
Leadership

If you look at the syntax of the Add-VMHost cmdlet, you'll notice that the Name parameter doesn't take an array of values, just a single String.

So you can only give it 1 hostname.


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

0 Kudos