Thursday, May 1, 2014

Deep in side DNS Server, DNS and WMI

All Microsoft Windows System Administrator know good information about DNS Server and how it work, and how to maintain it. but  do you really think that you know much.
There are a lot of hidden information in DNS Server that are not in GUI, these information can obtain using DNSCMD or WMI.
Today I will mention some of the hidden commands in Microsoft DNS (Namespace "MicrosoftDNS")
To make the query I will use PowerShell, So lets start:
Note: if you dont know much in powershell and want to use these scripts, then you can copy the script text and paste it to notepad, Save it as .ps1.
Open Powershell and then navigate to the script path and call it.
If you get an error regarding for execution policy, then use this command to first
Set-executionpolicy remotesigned

Get DNS Server Statistics
cls              
Param(            
[parameter(Mandatory=$True)]            
[string]$ServerName            
)            
Get-WmiObject -Class "MicrosoftDNS_Statistic" -Namespace "Root\MicrosoftDNS" -ComputerName $ServerName |Where{$_.value -gt 0} | FT DnsServerName,CollectionName,name,Value            
The Return result will show you a lot of details regarding for your DNS, like Timeout, Packets sent, LDAP information, Connection refused.

Get a list of all cached Domains in your DNS Server
In some case you may need to know which domains your DNS Server is caching. check this script

cls            
Param(            
[parameter(Mandatory=$True)]            
[string]$ServerName,            
[parameter(Mandatory=$True)]            
$DomainToExclude            
)            
Get-WmiObject -Class "MicrosoftDNS_AType" -Namespace "Root\MicrosoftDNS" -ComputerName $ServerName | Where{$_.domainname -notlike "*$DomainToExclude"} | select domainname,IPAddress,OwnerName}


The result will be a list of all the cached domains and its IP, This list may take some time to load if your DNS is loaded.

Read DS Polling Interval

When DNS Service Stored in AD, DNS Read AD information every 180 sec, To get these information.
Param(            
[parameter(Mandatory=$true)]            
$ServerName            
)
Get-WmiObject -Class "MicrosoftDNS_Server" -Namespace "Root\MicrosoftDNS" -ComputerName $ServerName | FT -AutoSize @{N="Polling Interval/ Sec";E={$_.DsPollingInterval}}


Change DS Polling Interval
If you want to change this value, you can use the following script

param(            
[parameter(Mandatory=$true)]            
$ServerName,            
[parameter(Mandatory=$true)]            
[int]$NewInterval            
)
$DSInterval=Get-WmiObject  -Namespace "Root\MicrosoftDNS" -Class "MicrosoftDNS_Server" -ComputerName $ServerName            
write-host "Old Value was "$DSInterval.DsPollingInterval            
$DSInterval.DsPollingInterval=$NewInterval            
$DSInterval.Put() |Out-Null            
write-host "New Value was "$DSInterval.DsPollingInterval            
}

Change DNS Error Log Level

If you want to change how much of events are written in Windows Eventlog, then you can take the control from here        
#0 None.            
#1 Log only errors.            
#2 Log only warnings and errors.            
#4 Log all events.            
            
Param(            
[parameter(Mandatory=$true)]            
$ServerName,            
[parameter(Mandatory=$true)]            
[int]$LoggingLevel            
)            
            
$x=Get-WmiObject -Namespace "root\microsoftdns" -Class "MicrosoftDNS_Server"            
$x.EventLogLevel=$LoggingLevel            
$x.Put() |Out-Null            
Write-Host "The Current Logging level is set to "$x.EventLogLevel            

I hope you like this..if so please share it or comment or like or what ever you want .
Thanks for reading

No comments: