DNS Library Server Control Zone Write Action

Microsoft.Windows.DNSServer.Library.WriteAction.ControlZone (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.ControlZone" Accessibility="Internal" RunAs="Microsoft.Windows.DNSServer.Library.ActionAccount" Batching="false">
<Configuration>
<xsd:element minOccurs="1" name="Server" type="xsd:string"/>
<xsd:element minOccurs="1" name="Zone" type="xsd:string"/>
<xsd:element minOccurs="1" name="Action" type="xsd:string"/>
</Configuration>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="WA" TypeID="Windows!Microsoft.Windows.ScriptWriteAction">
<ScriptName>ControlZone.vbs</ScriptName>
<Arguments>$Config/Server$ $Config/Zone$ $Config/Action$</Arguments>
<ScriptBody><Script>

'
' ControlZone.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 Zone"

strServer = WScript.Arguments(0)
strZone = WScript.Arguments(1)
strCommand = WScript.Arguments(2)

On Error Resume Next
Set objDNSWMI = GetObject("winmgmts:\\" &amp; strServer &amp; "\root\MicrosoftDNS")
If Err &lt;&gt; 0 Then Call ThrowScriptErrorAndAbort("Unable to connect to MicrosoftDNS namespace.")

Set colZones = objDNSWMI.ExecQuery("Select * from MicrosoftDNS_Zone where name = '" &amp; strZone &amp; "'")
If (Err &lt;&gt; 0) Then Call ThrowScriptErrorAndAbort("Unable to identify specified zone.")
If (colZones.Count=0) Then Call ThrowScriptErrorAndAbort("Zone not found.")

For Each objZone In colZones

Select Case lcase(strCommand)
Case "pause"
objZone.PauseZone
Case "resume"
objZone.ResumeZone
Case "reload"
objZone.ReloadZone
Case "refresh"
objZone.ForceRefresh
Case "update"
objZone.UpdateFromDS
Case Else
Call ThrowScriptErrorAndAbort("Bad command specified.")
End Select

If Err &lt;&gt; 0 Then Call ThrowScriptErrorAndAbort("Unable to perform specified action.")

'If we reach this point, assume we have succeeded.
strMessage = SCRIPT_NAME &amp; " completed successfully." &amp; VbCrLf &amp; _
"Zone: " &amp; strZone &amp; VbCrLf &amp; _
"Command: " &amp; strCommand &amp; VbCrLf
WScript.Echo strMessage

Next



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>