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

# 先定义 DNS 服务器

$dnsalt = "10.141.240.22"

# 指定 NTP 服务器地址

$ntpone = "10.101.1.151"

# 指定需要设置的主机,如下例子为vcenter 集群 Local 下所有主机地址

$esxHosts = Get-Cluster -Name Local | Get-VMhost

# 循环语句设置每台机子的 dns 和 ntp 地址

foreach ($esx in $esxHosts) {

Get-VMHostNetwork -VMHost $esx | Set-VMHostNetwork -DNSAddress $dnsalt -Confirm:$false

Add-VMHostNTPServer -NtpServer $ntpone -VMHost $esxHosts -Confirm:$false

# 设置 ntp 服务为随主机启动

Get-VMHostService -VMHost $esx | where{$_.Key -eq "ntpd"} | Set-VMHostService -policy "on" -Confirm:$false

# 重启 ntp 服务

Get-VMHostService -VMHost $esx | where{$_.Key -eq "ntpd"} | Restart-VMHostService -Confirm:$false

}


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