I need to check the Server Roles installed on the Windows 2008 Server R2 Machine. I have written a VBScript to Check the Server Roles installed via the ServerManagercmd.exe which creates a XML file.

I need to read the XML files and based on the Install tag need to stop the installation. I have written the below VBScript, Im not sure its right or wrong. But it checks the Roles ID's values and display the values. But im not getting the node names such as ID, Installed,Name.

The VBScript :
Dim WindowStyle
WindowStyle = 0 '0 for hidden, 4 to show it
Dim intExitCode
Dim Executable, Parameters,Query,Xml_file
Dim objNodeList
Dim arrResponse()
Dim intIndexSet
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.shell")
Xml_file=objShell.ExpandEnvironmentStrings("%temp%") & "/Server_roles.xml"
Executable = objShell.ExpandEnvironmentStrings("%windir%") & "/system32/ServerManagerCmd.exe "
Parameters = "-Query " & Xml_file
Query=Executable & Parameters
intExitCode = objShell.Run(Query, 0, True)
openFile = False
If objFSO.FileExists(Xml_file) Then
Set objDoc = CreateObject("Microsoft.XMLDOM")
objDoc.Async = False
objDoc.Load Xml_file
openFile = True
Set objNodeList = objDoc.documentElement.selectNodes("Role/@Id")
ReDim arrResponse(objNodeList.length - 1)

For intIndex = 0 To objNodeList.length - 1
arrResponse(intIndex) = objNodeList.item(intIndex).Text
if (objNodeList.item(intIndex).Text="Web-Server" OR objNodeList.item(intIndex).Text="Application-Server" ) then

Set objNamedNodeMap = objDoc.documentElement.childNodes(intIndex).Attributes
For i = 0 To (objNamedNodeMap.length - 1)
Set objNamedNodeMap1 = objDoc.documentElement.childNodes(intIndex)
Set objNode = objNamedNodeMap.nextNode
MsgBox objNode.Text

end if


getField = arrResponse


End If

Set objFSO = Nothing

And the Partial XML file is :

ServerManagerConfigurationQuery Time="2011-09-21T16:52:37" Language="en" xmlns="http://schemas.microsoft.com/sdm/Windows/ServerManager/Configuration/2007/1">
<Role DisplayName="Active Directory Certificate Services" Installed="false" Id="AD-Certificate">
<RoleService DisplayName="Certification Authority" Installed="false" Id="ADCS-Cert-Authority" Default="true" />
<RoleService DisplayName="Certification Authority Web Enrollment" Installed="false" Id="ADCS-Web-Enrollment" />
<RoleService DisplayName="Certificate Enrollment Web Service" Installed="false" Id="ADCS-Enroll-Web-Svc" />
<RoleService DisplayName="Certificate Enrollment Policy Web Service" Installed="false" Id="ADCS-Enroll-Web-Pol" />
<Role DisplayName="Active Directory Domain Services" Installed="false" Id="AD-Domain-Services">
<RoleService DisplayName="Active Directory Domain Controller" Installed="false" Id="ADDS-Domain-Controller" Default="true" />
<RoleService DisplayName="Identity Management for UNIX" Installed="false" Id="ADDS-Identity-Mgmt">
<RoleService DisplayName="Server for Network Information Services" Installed="false" Id="ADDS-NIS" />
<RoleService DisplayName="Password Synchronization" Installed="false" Id="ADDS-Password-Sync" />
<RoleService DisplayName="Administration Tools" Installed="false" Id="ADDS-IDMU-Tools" />

Let me know if there is any other way or any suggestions on the scripts

0 Comments   [ - ] Hide Comments


Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
Answer this question or Comment on this question for clarity


seems over complicated to me you just need to do this

Set objNodeList = objDoc.documentElement.selectNodes("Role/@Id")

for each objChildNode in objNodelist.childnodes
strId = objChildNode.GetAttribute("Id")
strInstalled = objChildNode.GetAttribute("Installed")

you can work out the rest.
Answered 09/23/2011 by: jmcfadyen
Fifth Degree Black Belt

Please log in to comment
Thanks a lot for the response. I have written a similar script and it works fine and stops the installation if there are no server roles being installed

Answered 09/26/2011 by: manitha21
Senior Yellow Belt

Please log in to comment