PowerCLI

 View Only
  • 1.  DNS SearchDomain

    Posted Sep 03, 2008 02:28 PM

    This little one is annoying me.

    Trying to set the SearchDomain for the ESX host.

    Set-vmhostnetwork doesn't allow you to pass a searchdomain param that I've seen. You clearly see the data in the get-vmhost | get-view.



  • 2.  RE: DNS SearchDomain
    Best Answer

    Posted Sep 03, 2008 06:13 PM

    With the UpdateDnsConfig method of the SDK it can be done like this

    $domains = ("mydomain.test", "and.another.domain")
    
    $esx = Get-VMHost -Name esx1.test.local | Get-View
    $ns = Get-View -Id $esx.configManager.networkSystem
    $dns = $ns.networkConfig.dnsConfig
    
    foreach($domainname in $domains) {
      $dns.SearchDomain += $domainname
    }
    
    $ns.UpdateDnsConfig($dns)
    

    The above script will add additional domains to the current SearchDomain content.

    If you want to replace the contents of the SearchDomain completely it can be done like this

    $domains = ("test.local", "and.another.domain")
    
    $esx = Get-VMHost -Name esx1.test.local | Get-View
    $ns = Get-View -Id $esx.configManager.networkSystem
    $dns = $ns.networkConfig.dnsConfig
    
    $dns.SearchDomain = @()
    
    foreach($domainname in $domains) {
      $dns.SearchDomain += $domainname
    }
    
    $ns.UpdateDnsConfig($dns)
    



  • 3.  RE: DNS SearchDomain

    Posted Sep 03, 2008 06:29 PM

    Thanks LucD.