c# - Delete host from dns zone -
i trying delete host using below code selected zone not deleting.
string query = "select * microsoftdns_zone containername = '" + zonename + "' , ownername='" + recordname + "'"; objectquery qry = new objectquery(query); managementscope scope = new managementscope(@"\\" + dnsservername + "\\root\\microsoftdns"); scope.connect(); managementobjectsearcher s = new managementobjectsearcher(scope, qry); managementobjectcollection col = s.get(); foreach (managementobject obj in col) { obj.delete(); }
please help.
below code delete domain record.
bool deleterecordfromdns(string zonename, string dnsservername, string recordname) { try { string query = string.format("select * microsoftdns_atype ownername = '{0}.{1}'", recordname, zonename); objectquery qry = new objectquery(query); managementscope scope = new managementscope(@"\\" + dnsservername + "\\root\\microsoftdns"); scope.connect(); managementobjectsearcher s = new managementobjectsearcher(scope, qry); managementobjectcollection col = s.get(); if (col.count > 0) { foreach (managementobject obj in col) { obj.delete(); } return true; } else { return false; } } catch (exception) { return false; } }
Comments
Post a Comment