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)