更多vsphere自动化运维视频课程

#定义标准交换机

$vswitch = "vSwitch2"  

#获取Production下的esxi主机

$vmhosts = Get-Cluster -Name Production | Get-VMHost

#遍历每台esxi主机,并在标准交换机"vSwitch2"  上创建端口组

foreach($vmhost in $vmhosts)

{

Get-VMHost -name $VMhost | Get-VirtualSwitch -name $vswitch | New-VirtualPortGroup -name VLAN49 -VLanId 49

Get-VMHost -name $VMhost | Get-VirtualSwitch -name $vswitch | New-VirtualPortGroup -name VLAN48 -VLanId 48

Get-VMHost -name $VMhost | Get-VirtualSwitch -name $vswitch | New-VirtualPortGroup -name VLAN47 -VLanId 47

}

#说明:

1、在你的环境中,只需更换集群名称和标准交换机名,以及对应的端口组名字、端口组配置的VLAN信息,其他无需改动

2、若创建多和端口,在foreach循环体内写多行即可

3、若在foreach循环体内只写一行命令,可将端口组名称、端口组VLAN等信息通过csv文件方式引入,将端口组名字和端口组的VLAN定义成变量

更多vsphere自动化运维视频课程