'
'
' ControlDNSServer.vbs
' Intended to be called interactively from a Task.
' Output will be sent through WScript.Echo and not in Windows events.
SetLocale("en-us")
Const SCRIPT_NAME = "Control DNS Server"
strCommand = WScript.Arguments(0)
On Error Resume Next
Set objDNSWMI = GetObject("winmgmts:\\.\root\MicrosoftDNS")
If Err <> 0 Then Call ThrowScriptErrorAndAbort("Unable to connect to MicrosoftDNS namespace.")
Select Case lcase(strCommand)
Case "scavenge"
Set colServers = objDNSWMI.ExecQuery("Select * from MicrosoftDNS_Server")
If (Err <> 0) Then Call ThrowScriptErrorAndAbort("Unable to query MicrosoftDNS_Server class.")
For Each objServer In colServers
objServer.StartScavenging
Next
WScript.Echo "Scavening successfully started."
Case "clearcache"
Set colCache = objDNSWMI.ExecQuery("Select * from MicrosoftDNS_Cache")
If (Err <> 0) Then Call ThrowScriptErrorAndAbort("Unable to query MicrosoftDNS_Cache class.")
For Each objCache In colCace
objCache.ClearCache
Next
WScript.Echo "Cache successfully cleared."
Case Else
Call ThrowScriptErrorAndAbort("Bad command specified.")
End Select
Sub ThrowScriptErrorAndAbort(strMessage)
strMessage = SCRIPT_NAME & " completed with an error." & VbCrLf & _
strMessage & VbCrLf & VbCrLf & _
"Server: " & strServer & VbCrLf & _
"Zone: " & strZone & VbCrLf & _
"Command: " & strCommand & VbCrLf
If Err <> 0 Then strMessage = strMessage & "Error: " & Err.Number & " - " & Err.Description & VbCrLf