Hi,
is there a way to change the DNS server on every host via the powershell?
Thanks
Chris
Sure, something like this should do the trick
$dnsServers = ("192.168.111.3","192.168.111.4") Get-VMHost | Get-View | %{ $ns = Get-View -Id $_.configManager.networkSystem $dns = $ns.networkConfig.dnsConfig $dns.Address = @() foreach($server in $dnsServers) { $dns.Address += $server } $ns.UpdateDnsConfig($dns) }
It looks as if an ESX server accepts only 2 DNS servers.
Message was edited by: LucD
Corrected error in the script.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
There was a dot (.) missing in the foreach line.
foreach($server in $dns.Servers) {
Sorry about that.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Is there a way to change just the 2. DNS Server?
And also check if the first has the same IP that i want to fill into the 2.?
And when that is true it should change first an 2. IP.
Is that possible?
You could do something like this
$esxName = <esx-name> $new2ndIP = "192.168.111.1" $net = Get-VMHost $esxName | Get-VMHostNetwork $dns = $net.DnsAddress if($dns[0] -eq $new2ndIP){ Write-Host "First DNS IP address is the same" $new2ndIP = Read-Host "Enter new IP address" } $dns[1] = $new2ndIP $net | Set-VMHostNetwork -DnsAddress $dns
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference