#add distributed switch to datacenter
New-VDSwitch -Name vds-vmotion -Location Dtarget
New-VDSwitch -Name vds-prd -Location Dtarget
New-VDSwitch -Name vds-storage -Location Dtarget
#add portgroup to distributed switch
Get-VDSwitch vds-prd | New-VDPortgroup -Name 192.168.10.0 -VlanId 10
Get-VDSwitch vds-vmotion | New-VDPortgroup -Name 192.168.2.0 -VlanId 2
Get-VDSwitch vds-storage | New-VDPortgroup -Name 192.168.100.0 -VlanId 100
$vmhostlist = import-csv E:\vmhostlist.csv
foreach ($vmhost in $vmhostlist){
#config dns,domainname,ntpserver to vmhost
Get-VMHostNetwork -VMHost $vmhost.ip | Set-VMHostNetwork -DnsFromDhcp $false -DnsAddress 192.168.1.254 -DomainName test.org
Add-VMHostNtpServer -VMHost $vmhost.ip -NtpServer 192.168.1.254
Get-VMHostService -VMHost $vmhost.ip | where {$_.Key -eq "ntpd"} | Start-VMHostService
Get-VMHostService -VMHost $vmhost.ip | where {$_.Key -eq "ntpd"} | Set-VMHostService -Policy Automatic
#add vmhost to distributed switch
Get-VDSwitch -Name vds-* | Add-VDSwitchVMHost -VMHost $vmhost.ip
#add physicol adapter to standard switch up link
$myVMHostNetworkAdapter = Get-VMhost $vmhost.ip | Get-VMHostNetworkAdapter -Physical -Name vmnic1
Get-VirtualSwitch -VMHost $vmhost.ip -Name "vSwitch0" | Add-VirtualSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $myVMHostNetworkAdapter -Confirm:$false
#add physicol adapter to distributed switch up link
$nic = Get-VMhost $vmhost.ip| Get-VMHostNetworkAdapter -Physical -Name vmnic2,vmnic3
Get-VDSwitch -VMHost $vmhost.ip -Name vds-prd | Add-VDSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $nic -Confirm:$false
$nic = Get-VMhost $vmhost.ip| Get-VMHostNetworkAdapter -Physical -Name vmnic4,vmnic5
Get-VDSwitch -VMHost $vmhost.ip -Name vds-vmotion | Add-VDSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $nic -Confirm:$false
$nic = Get-VMhost $vmhost.ip | Get-VMHostNetworkAdapter -Physical -Name vmnic6,vmnic7
Get-VDSwitch -VMHost $vmhost.ip -Name vds-storage | Add-VDSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $nic -Confirm:$false
#add vmkernel vMotion adn vsan traffic
New-VMHostNetworkAdapter -VMHost $vmhost.ip -VirtualSwitch vds-vmotion -PortGroup 192.168.2.0 -IP $vmhost.vmotionip -SubnetMask 255.255.255.0 -VMotionEnabled $true
New-VMHostNetworkAdapter -VMHost $vmhost.ip -VirtualSwitch vds-storage -PortGroup 192.168.100.0 -IP $vmhost.storageip -SubnetMask 255.255.255.0 -VsanTrafficEnabled $true
}本文出自 “汜水流年_” 博客,请务必保留此出处http://timefiles.blog.51cto.com/8475652/1967853
原文:http://timefiles.blog.51cto.com/8475652/1967853