Ive tried many that have been posted around the web and none work... Anyone have a script to change the DNS entries on all hosts?
Ok, changed a few bits my end, it wasnt working but now is... try this (50% confident
$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) }
If you found this information useful, please consider awarding points for Correct or Helpful.
Alan Renouf
Have you tried LucD's answer on a recent post... http://communities.vmware.com/message/1049343#1049343
$dnsServers = ("192.168.111.3","192.168.111.4") Get-VMHost | Get-View | %{ $ns = Get-View -Id $esx.configManager.networkSystem $dns = $ns.networkConfig.dnsConfig $dns.Address = @() foreach($server in $dnsServers) { $dns.Address += $server } $ns.UpdateDnsConfig($dns) }
If you found this information useful, please consider awarding points for Correct or Helpful.
Alan Renouf
I have and it doesnt seem to work.....
Property 'Address' cannot be found on this object; make sure it exists and is s
ettable.
At line:6 char:12
+ $dns.A <<<< ddress += $server
Property 'searchDomain' cannot be found on this object; make sure it exists and
is settable.
At line:8 char:8
Saying that, I get the same Let me have a look !
If you found this information useful, please consider awarding points for Correct or Helpful.
Alan Renouf
Ok, changed a few bits my end, it wasnt working but now is... try this (50% confident
$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) }
If you found this information useful, please consider awarding points for Correct or Helpful.
Alan Renouf
That worked!!!! Awesome!
Thanks a bunch!
Could I limit the script by datacenters? or even better exclude on eor two datacenters?
Here is my problem.. I need to change the primary and secondary DNS server on all local ESX servers but leave branch office ESX servers alone.
Mostly they slide nicely into different datacenters but in some cases they are mixed.
local servers are all on 192.168.8-15.x subnets... and branch servers are different so I do ot wish to touch their DNS servers.
I figure I can go in manually and change the datacenters that have mixed content.. only talking about 20-30 hosts but the rest would be nice to have a script for about 170 of them.
You can easily limit the returned hosts to a specific datacenter.
Change the start of the loop to
Get-VMHost -Location (Get-Datacenter -Name $dcName) | Get-View | %{ ...
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This being my first excursion into the PowerCLI that I just now
installed... do I just copy this script in? or make it into a file of
some sorts and upload it somewhere and run it?
Store the script in a .ps1 file.
Start the PowerCLI prompt.
Connect to the vCenter or an ESX(i) host.
Connect-VIServer -Server name....
At the prompt type the name of the script to execute
.\ESX-change-DNS.ps1
Jonathan wrote a very good PowerCLI intro
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
this can also be done as a oneliner!
get-cluster "Test Cluster" | get-vmhost | get-vmhostnetwork | set-vmhostnetwork -dnsaddress "192.168.1.1","192.168.1.2"
Sweet!!! That worked like a charm!
Thank you very much!
When this runs, will I be prompted to enter the datacenter name?
No, you have to store the datacentername in the variable $dcName
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference