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?
$cluster = get-cluster -name "WDC"
$strcomputers = "host1", "host2"
$strcomputers | foreach {add-vmhost -name $_ -location $cluster -user root -password "xxxxxxxxxx" -confirm:$false}
thank you. just wondering why this line does not work
add-vmhost -name $strcomputers -location $cluster -user root -password "xxxxxxxxxx" -confirm:$false
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