# DNS Servers $dnspri = "192.168.161.203" $dnsalt = "192.168.161.213" # Domain Name $domainname = "test.org" # NTP Servers $ntpone = "192.168.168.253" #Default Gateway $dg = "192.168.165.254" $esxHosts = get-VMHost #esxHost = import-csv c:\test.csv foreach ($esx in $esxHosts) { Write-Host "add physical network adapter to vswitch" -ForegroundColor Green $myVMHostNetworkAdapter = Get-VMhost $esx | Get-VMHostNetworkAdapter -Physical -Name vmnic0,vmnic1 Get-VirtualSwitch -VMHost 192.168.1.11 -Name "vSwitch0" | Add-VirtualSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $myVMHostNetworkAdapter Write-Host "Configuring DNS and Domain Name on $esx" -ForegroundColor Green Get-VMHostNetwork -VMHost $esx | Set-VMHostNetwork -DomainName $domainname -DNSAddress $dnspri , $dnsalt -Confirm:$false Write-Host "Configuring Default Gateway IP on $esx" -ForegroundColor Green Get-VMHostNetwork -VMHost $esx | Set-VMHostNetwork -ConsoleGateway $dg Write-Host "Configuring hostname on $esx" -ForegroundColor Green Get-VMHostNetwork -VMHost $esx | Set-VMHostNetwork -HostName $esx.Name Write-Host "Configuring NTP Servers on $esx" -ForegroundColor Green Add-VMHostNTPServer -NtpServer $ntpone -VMHost $esx -Confirm:$false Write-Host "Configuring NTP Client Policy on $esx" -ForegroundColor Green Get-VMHostService -VMHost $esx | where{$_.Key -eq "ntpd"} | Set-VMHostService -policy "on" -Confirm:$false Write-Host "Restarting NTP Client on $esx" -ForegroundColor Green Get-VMHostService -VMHost $esx | where{$_.Key -eq "ntpd"} | Restart-VMHostService -Confirm:$false }
转载于:https://blog.51cto.com/timefiles/1967512