VBscript,Server Roles and XML
ello,
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
Next
end if
Next
getField = arrResponse
Else
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>
<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" />
</RoleService>
</Role>
Let me know if there is any other way or any suggestions on the scripts
Regards,
MS
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
Next
end if
Next
getField = arrResponse
Else
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>
<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" />
</RoleService>
</Role>
Let me know if there is any other way or any suggestions on the scripts
Regards,
MS
0 Comments
[ + ] Show comments
Answers (2)
Please log in to answer
Posted by:
jmcfadyen
13 years ago
Posted by:
manitha21
13 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.