DNS Library Server Control Server Write Action

Microsoft.Windows.DNSServer.Library.WriteAction.ControlServer (WriteActionModuleType)

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsMicrosoft.Windows.DNSServer.Library.ActionAccount
InputTypeSystem.BaseData
OutputTypeSystem.CommandOutput

Member Modules:

ID Module Type TypeId RunAs 
WA WriteAction Microsoft.Windows.ScriptWriteAction Default

Source Code:

<WriteActionModuleType ID="Microsoft.Windows.DNSServer.Library.WriteAction.ControlServer" Accessibility="Internal" RunAs="Microsoft.Windows.DNSServer.Library.ActionAccount" Batching="false">
<Configuration>
<xsd:element minOccurs="1" name="Action" type="xsd:string"/>
</Configuration>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="WA" TypeID="Windows!Microsoft.Windows.ScriptWriteAction">
<ScriptName>ControlDNSServer.vbs</ScriptName>
<Arguments>$Config/Action$</Arguments>
<ScriptBody><Script>

'
'
' 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 &lt;&gt; 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 &lt;&gt; 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 &lt;&gt; 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 &amp; " completed with an error." &amp; VbCrLf &amp; _
strMessage &amp; VbCrLf &amp; VbCrLf &amp; _
"Server: " &amp; strServer &amp; VbCrLf &amp; _
"Zone: " &amp; strZone &amp; VbCrLf &amp; _
"Command: " &amp; strCommand &amp; VbCrLf
If Err &lt;&gt; 0 Then strMessage = strMessage &amp; "Error: " &amp; Err.Number &amp; " - " &amp; Err.Description &amp; VbCrLf

WScript.Echo strMessage
WScript.Quit

End Sub

'</Script></ScriptBody>
<TimeoutSeconds>30</TimeoutSeconds>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="WA"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.CommandOutput</OutputType>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>