【发布时间】:2020-01-26 22:33:29
【问题描述】:
我正在尝试使用 PowerCLI 为 vCenter 中的现有 ESXi 主机创建 vmkernel。
$esxiHosts = @("esxi21.v.lab", "esxi22.v.lab", "esxi23.v.lab", "esxi24.v.lab", "esxi25.v.lab")
$vmhosts = Get-VMHost -Name $esxiHosts
foreach ($i in 31..35)
{
$ipa = "192.168.2.$i"
write-host $vmhosts
$esxiHosts | foreach-object {New-VMHostNetworkAdapter $_ -PortGroup ManagementNetwork2 -IP $ipa -subnetmask 255.255.255.0 -VirtualSwitch vSwitch0 -ManagementTrafficEnabled $true}
}
它为每个主机创建 vmkernel,但为所有主机分配相同的 IP 地址,然后也显示以下错误。
New-VMHostNetworkAdapter : 26 Sep 2019 4:21:17 PM New-VMHostNetworkAdapter An error occurred during host configuration. Operation failed, diagnostics report: A vmkernel
nic for the connection point already exists:
At line:5 char:30
+ ... ach-object {New-VMHostNetworkAdapter $_ -PortGroup ManagementNetwork2 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-VMHostNetworkAdapter], PlatformConfigFault
+ FullyQualifiedErrorId : Client20_VmHostServiceImpl_NewVMHostNetworkAdapter_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.NewVMHostNetworkAdapter
我的理解是这是由于循环内运行的 foreach 对象,但如果我不这样做,我将无法仅使用 for each 循环来迭代 IP 地址,或者我可以吗?
【问题讨论】: