CherryPanda
MIS
Hello,
I'm a long-time user / first time poster on these forums. This is my contribution, if anyone finds it helpful or has improvement ideas - great!
Synapse - VBScript is great for collection various data from AD but there aren't many ways to store/present complex data sets. Using XMLDOM allows us to have a navigational structure and data repository in one and this is how I choose to implement it:
Const adPersistXML = 1
Const adVarChar = 200
Const MaxCharacters = 255
Const adFldIsNullable = 32
Dim objBranches, objBranch, colLoggedEvents, objRSEvents
Set objConn = createobject("ADODB.Connection")
set objComm = createobject("ADODB.Command")
Set iAdRootDSE = GetObject("LDAP://RootDSE")
Set objTreeXML = CreateObject("MSXML2.DOMDocument")
objTreeXML.async = False
strNC = iAdRootDSE.Get("configurationNamingContext")
strNC = "CN=Administrative Groups,CN=fabrikam,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=fabrikam,DC=com"
strTop = "CN=Administrative Groups,CN=fabrikam,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=fabrikam,DC=com"
strCounter = 1
strPrevClass = "Top"
strPrevClust = ""
objConn.Provider = "ADsDSOObject"
objConn.Open "ADs Provider"
objComm.ActiveConnection = objConn
On Error Resume Next
Set objRoot = objTreeXML.createElement("Top")
objTreeXML.appendChild objRoot
Set objAttr = objTreeXML.createAttribute("CN")
objAttr.Text = strNC
objRoot.attributes.setNamedItem objAttr
arrTree = Array("msExchAdminGroup","msExchExchangeServer","msExchStorageGroup","msExchPrivateMDB")
For Each strLevel In arrTree
Call BuildTree(strLevel)
Next
objConn.Close
Set objComm = Nothing
Set objConn = Nothing
Sub BuildTree(strLevel)
Set objBranches = objTreeXML.getElementsByTagName(strPrevClass)
For Each objBranch In objBranches
strNC = BuildDN(objBranch)
objComm.CommandText = "SELECT cn, distinguishedName FROM 'LDAP://" & strNC & "'"_
& " WHERE objectCategory='" & strLevel & "' "_
& " ORDER By cn"
Set objRS = objComm.Execute
If Not objRS.EOF Then
objRS.MoveFirst
End If
While Not objRS.EOF
Set objRecord = objTreeXML.createElement(strLevel)
Set objAttr = objTreeXML.createAttribute("CN")
objAttr.Text = objRS("CN")
objRecord.Attributes.setNamedItem objAttr
If strLevel = "msExchExchangeServer" Then
Set objAttr = objTreeXML.createAttribute("Access")
objAttr.Text = True
objRecord.Attributes.setNamedItem objAttr
End If
objBranch.appendChild objRecord
objRS.MoveNext
Wend
objRS.Close
Set objRS = Nothing
Next
strPrevClass = strLevel
End Sub
Function BuildDN(objNode)
Set objBranchTest = objNode
BuildDN = ""
Do While objBranchTest.parentNode.nodeName <> "#document"
Select Case objBranchTest.TagName
Case "msExchAdminGroup"
BuildDN = BuildDN & "CN=" & objBranchTest.attributes.item(0).text
Case "msExchExchangeServer"
BuildDN = BuildDN & "CN=" & objBranchTest.attributes.item(0).text & ",CN=Servers,"
Case "msExchStorageGroup"
BuildDN = BuildDN & "CN=" & objBranchTest.attributes.item(0).text & ",CN=InformationStore,"
Case "msExchPrivateMDB"
BuildDN = BuildDN & "CN=" & objBranchTest.attributes.item(0).text & ","
End Select
Set objBranchTest = objBranchTest.parentNode
Loop
If Len(BuildDN) = 0 Then
BuildDN = strTop
End If
If Trim(UCase(BuildDN)) <> Trim(UCase(strTop)) Then
BuildDN = BuildDN & "," & strTop
End If
End Function
objTreeXML.save "ExcTree.xml"
This example is specific to building XML for MS Exchange and later using it to collect / store / present various aspects:
<Top CN="CN=Administrative Groups,CN=fabrikam,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=fabrikam,DC=com">
<msExchAdminGroup CN="VISN 04">
<msExchExchangeServer CN="SITELOC1MSGA1" Access="-1" Cluster="SITELOC1CLUA1">
<msExchStorageGroup CN="Storage Group 1 (SITELOC1MSGA1)" LogPath="F:\sg1Logs" DBTotal="409.95" DBFree="241.94" LogTotal="38.99" LogFree="33.09">
<msExchPrivateMDB CN="SG1 DB1 (SITELOC1MSGA1)" EDB="48.92" STM="3.39" WS="5.17" />
<msExchPrivateMDB CN="SG1 DB2 (SITELOC1MSGA1)" EDB="24.83" STM="3.52" WS="1.18" />
</msExchStorageGroup>
</msExchExchangeServer>
</msExchAdminGroup>
<msExchAdminGroup CN="VISN 05">
<msExchExchangeServer CN="SITELOC2MSGA1" Access="-1" Cluster="SITELOC2CLUA1">
<msExchPrivateMDB CN="SG2 DB4 (SITELOC2MSGA1)" EDB="0" STM="0" WS="0" />
</msExchStorageGroup>
<msExchStorageGroup CN="Storage Group 1 (SITELOC2MSGA1)" LogPath="F:\sg1Logs" DBTotal="409.95" DBFree="218.31" LogTotal="38.99" LogFree="31.31">
<msExchPrivateMDB CN="SG1 DB1 (SITELOC2MSGA1)" EDB="45.73" STM="4.21" WS="2.63" />
<msExchPrivateMDB CN="SG1 DB2 (SITELOC2MSGA1)" EDB="30.71" STM="3.08" WS="0.36" />
</msExchStorageGroup>
<msExchStorageGroup CN="Storage Group 2 (SITELOC2MSGA1)" LogPath="F:\sg2Logs" DBTotal="409.95" DBFree="216.56" LogTotal="38.99" LogFree="31.38">
<msExchPrivateMDB CN="SG2 DB1 (SITELOC2MSGA1)" EDB="31.50" STM="2.69" WS="2.30" />
<msExchPrivateMDB CN="SG2 DB2 (SITELOC2MSGA1)" EDB="36.75" STM="4.53" WS="1.38" />
</msExchStorageGroup>
</msExchExchangeServer>
<msExchStorageGroup CN="Storage Group 1 (SITELOC2MSGS)" LogPath="L:\exchsrvr\mdbdata">
<msExchPrivateMDB CN="SG1 DB1 (SITELOC2MSGS)" EDB="2.51" STM="0.12" WS="0" />
</msExchStorageGroup>
</msExchExchangeServer>
</msExchAdminGroup>
</Top>
This example already has some information filled in, such as Exchange storage groups drive sizes, EDB/STM, White Space and so on.
I'm a long-time user / first time poster on these forums. This is my contribution, if anyone finds it helpful or has improvement ideas - great!
Synapse - VBScript is great for collection various data from AD but there aren't many ways to store/present complex data sets. Using XMLDOM allows us to have a navigational structure and data repository in one and this is how I choose to implement it:
Const adPersistXML = 1
Const adVarChar = 200
Const MaxCharacters = 255
Const adFldIsNullable = 32
Dim objBranches, objBranch, colLoggedEvents, objRSEvents
Set objConn = createobject("ADODB.Connection")
set objComm = createobject("ADODB.Command")
Set iAdRootDSE = GetObject("LDAP://RootDSE")
Set objTreeXML = CreateObject("MSXML2.DOMDocument")
objTreeXML.async = False
strNC = iAdRootDSE.Get("configurationNamingContext")
strNC = "CN=Administrative Groups,CN=fabrikam,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=fabrikam,DC=com"
strTop = "CN=Administrative Groups,CN=fabrikam,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=fabrikam,DC=com"
strCounter = 1
strPrevClass = "Top"
strPrevClust = ""
objConn.Provider = "ADsDSOObject"
objConn.Open "ADs Provider"
objComm.ActiveConnection = objConn
On Error Resume Next
Set objRoot = objTreeXML.createElement("Top")
objTreeXML.appendChild objRoot
Set objAttr = objTreeXML.createAttribute("CN")
objAttr.Text = strNC
objRoot.attributes.setNamedItem objAttr
arrTree = Array("msExchAdminGroup","msExchExchangeServer","msExchStorageGroup","msExchPrivateMDB")
For Each strLevel In arrTree
Call BuildTree(strLevel)
Next
objConn.Close
Set objComm = Nothing
Set objConn = Nothing
Sub BuildTree(strLevel)
Set objBranches = objTreeXML.getElementsByTagName(strPrevClass)
For Each objBranch In objBranches
strNC = BuildDN(objBranch)
objComm.CommandText = "SELECT cn, distinguishedName FROM 'LDAP://" & strNC & "'"_
& " WHERE objectCategory='" & strLevel & "' "_
& " ORDER By cn"
Set objRS = objComm.Execute
If Not objRS.EOF Then
objRS.MoveFirst
End If
While Not objRS.EOF
Set objRecord = objTreeXML.createElement(strLevel)
Set objAttr = objTreeXML.createAttribute("CN")
objAttr.Text = objRS("CN")
objRecord.Attributes.setNamedItem objAttr
If strLevel = "msExchExchangeServer" Then
Set objAttr = objTreeXML.createAttribute("Access")
objAttr.Text = True
objRecord.Attributes.setNamedItem objAttr
End If
objBranch.appendChild objRecord
objRS.MoveNext
Wend
objRS.Close
Set objRS = Nothing
Next
strPrevClass = strLevel
End Sub
Function BuildDN(objNode)
Set objBranchTest = objNode
BuildDN = ""
Do While objBranchTest.parentNode.nodeName <> "#document"
Select Case objBranchTest.TagName
Case "msExchAdminGroup"
BuildDN = BuildDN & "CN=" & objBranchTest.attributes.item(0).text
Case "msExchExchangeServer"
BuildDN = BuildDN & "CN=" & objBranchTest.attributes.item(0).text & ",CN=Servers,"
Case "msExchStorageGroup"
BuildDN = BuildDN & "CN=" & objBranchTest.attributes.item(0).text & ",CN=InformationStore,"
Case "msExchPrivateMDB"
BuildDN = BuildDN & "CN=" & objBranchTest.attributes.item(0).text & ","
End Select
Set objBranchTest = objBranchTest.parentNode
Loop
If Len(BuildDN) = 0 Then
BuildDN = strTop
End If
If Trim(UCase(BuildDN)) <> Trim(UCase(strTop)) Then
BuildDN = BuildDN & "," & strTop
End If
End Function
objTreeXML.save "ExcTree.xml"
This example is specific to building XML for MS Exchange and later using it to collect / store / present various aspects:
<Top CN="CN=Administrative Groups,CN=fabrikam,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=fabrikam,DC=com">
<msExchAdminGroup CN="VISN 04">
<msExchExchangeServer CN="SITELOC1MSGA1" Access="-1" Cluster="SITELOC1CLUA1">
<msExchStorageGroup CN="Storage Group 1 (SITELOC1MSGA1)" LogPath="F:\sg1Logs" DBTotal="409.95" DBFree="241.94" LogTotal="38.99" LogFree="33.09">
<msExchPrivateMDB CN="SG1 DB1 (SITELOC1MSGA1)" EDB="48.92" STM="3.39" WS="5.17" />
<msExchPrivateMDB CN="SG1 DB2 (SITELOC1MSGA1)" EDB="24.83" STM="3.52" WS="1.18" />
</msExchStorageGroup>
</msExchExchangeServer>
</msExchAdminGroup>
<msExchAdminGroup CN="VISN 05">
<msExchExchangeServer CN="SITELOC2MSGA1" Access="-1" Cluster="SITELOC2CLUA1">
<msExchPrivateMDB CN="SG2 DB4 (SITELOC2MSGA1)" EDB="0" STM="0" WS="0" />
</msExchStorageGroup>
<msExchStorageGroup CN="Storage Group 1 (SITELOC2MSGA1)" LogPath="F:\sg1Logs" DBTotal="409.95" DBFree="218.31" LogTotal="38.99" LogFree="31.31">
<msExchPrivateMDB CN="SG1 DB1 (SITELOC2MSGA1)" EDB="45.73" STM="4.21" WS="2.63" />
<msExchPrivateMDB CN="SG1 DB2 (SITELOC2MSGA1)" EDB="30.71" STM="3.08" WS="0.36" />
</msExchStorageGroup>
<msExchStorageGroup CN="Storage Group 2 (SITELOC2MSGA1)" LogPath="F:\sg2Logs" DBTotal="409.95" DBFree="216.56" LogTotal="38.99" LogFree="31.38">
<msExchPrivateMDB CN="SG2 DB1 (SITELOC2MSGA1)" EDB="31.50" STM="2.69" WS="2.30" />
<msExchPrivateMDB CN="SG2 DB2 (SITELOC2MSGA1)" EDB="36.75" STM="4.53" WS="1.38" />
</msExchStorageGroup>
</msExchExchangeServer>
<msExchStorageGroup CN="Storage Group 1 (SITELOC2MSGS)" LogPath="L:\exchsrvr\mdbdata">
<msExchPrivateMDB CN="SG1 DB1 (SITELOC2MSGS)" EDB="2.51" STM="0.12" WS="0" />
</msExchStorageGroup>
</msExchExchangeServer>
</msExchAdminGroup>
</Top>
This example already has some information filled in, such as Exchange storage groups drive sizes, EDB/STM, White Space and so on.