I have finished the first in a series of AD Diagraming scripts using Kixtart and MS Visio 2003. The Script directly querries AD and builds a diagram with a list of Sites in your AD Domain. Currently the script has only been tested With AD 2003 but should work with AD 2000.

Pre-Requisites
* Visio 2003 Pro must be installed on the machine that the querry is running From
* Running Kixtart 4.51
* Must Include fnLDAPQuery() Udf. I named mine LDAP.UDF, change that to your UDF File.

Code:
 
; Script Name: Ad.CFG.Site.Overview.kix
; Author: Bryan Sockel
; ****************************************************************************************************
; Version Information
; ****************************************************************************************************

; Version 1.0
; Connects to the local active Directory Database and Pulls basic site information.
; Creates a Visio document and adds a site to the document currently with the following object custom
; properties
; * Name
; * allowedAttributes
; * allowedAttributesEffective
; * allowedChildClasses
; * allowedChildClassesEffective
; * canonicalName
; * cn
; * createTimeStamp
; * description
; * distinguishedName
; * fromEntry
; * instanceType
; * modifyTimeStamp
; * msDS-Approx-Immed-Subordinates
; * msDS-ReplAttributeMetaData
; * objectCategory
; * objectClass
; * sDRightsEffective
; * siteObjectBL
; * structuralObjectClass
; * subSchemaSubEntry
; * systemFlags
; * whenChanged
; * whenCreated

; ****************************************************************************************************
; Prerequisites
; ****************************************************************************************************
; In order for Script to work correctly, the PC that the script is run from must have the following:
; * Visio Professional, not Visio Standard Visio standard does not have the AD Stencils
; * Must Include the UDF for fnLDAPQuery()
; ****************************************************************************************************
; Main Script
; ****************************************************************************************************
;Cls
Break on

include ".\Ldap.UDF"
$PageCnt = 1
$StenRowCnt = 0

$AppVisio = CreateObject("visio.application")
$docsObj = $AppVisio.Documents
$DocObj = $docsObj.Add("ACTDIR_U.VST")
$pagsObj = $AppVisio.ActiveDocument.Pages
$pagObj = $pagsObj.Item(1)

; ****************************************************************************************************
; SiteOverView Diagram
; ****************************************************************************************************
SSpacing()
$ReportHeader = "AD Configuration - Site Overview Diagram" ; Text To appear at the top of the Report
$PageDesc = "SiteOV" ; Page Name
$pagObj.Name = "$PageDesc-P$Pagecnt"
$AppWindow = $AppVisio.ActiveWindow.Page
$Header = $AppWindow.DrawRectangle(0.2, 10.5, 8.2, 10.8) ; Create Title Box
$Header.TextStyle = "Normal"
$Header.LineStyle = "Text Only"
$Header.FillStyle = "Text Only"
$Header.Text = "$ReportHeader"
$aAttributes = "Name", "allowedAttributes", "allowedAttributesEffective", "allowedChildClasses",
"allowedChildClassesEffective", "canonicalName", "cn", "createTimeStamp",
"description", "distinguishedName", "fromEntry", "instanceType",
"modifyTimeStamp", "msDS-Approx-Immed-Subordinates",
"msDS-ReplAttributeMetaData", "objectCategory", "objectClass",
"sDRightsEffective", "siteObjectBL", "structuralObjectClass",
"subSchemaSubEntry", "systemFlags", "whenChanged", "whenCreated"
$sADsPath = "LDAP://"+GetObject("LDAP://rootDSE").Get("ConfigurationNamingContext")
$strFilter = "(&(objectClass=Site)(Name=*))"
$SiteResults = fnLDAPQuery($aAttributes,$sADsPath,$strFilter,"Name")
For $c = 0 to Ubound($SiteResults)
$A=AddStencil("ADO_U.vss","Site",$SiteResults[$c,$r])
For $r = 1 to UBound($SiteResults,2)

$Value = ""
IF Ubound($SiteResults[$c,$r]) <> "-1"
For Each $Element In $SiteResults[$c,$r]
If Len($Value) <> 0
$Value = "$Value,$Element"
Else
$Value = $Element
Endif
Next
Else
$Value = $SiteResults[$C,$R]
Endif
$=ACustomAttributes($aAttributes[$r],CStr($Value),$shpObj.id)

Next
Next

Function AddStencil($VSS,$ObjType,$ObjText);,$StencilX,$StencilY)
; ******************************************************************************************
; Function Creates Objects on Visio Document
; ******************************************************************************************
; Creating Object On Visio Diagram
$stnObj = $AppVisio.Documents($VSS)
$mastObj = $stnObj.Masters("$ObjType")
$shpObj = $pagObj.Drop($mastObj, "$StencilX", "$StencilY")
$shpObj.Text = "$ObjText"
$shpObj.Name = "$ObjText"
$shpObj.ID = "$ObjText"

; Icrementing Counters
$StencilX = Cstr(Cdbl($StencilX) + CDbl($StenXSp))

; Checking to see if they are at the end of the row
; If So Movin on to the next row.
If $StencilX >= 8.25
$StencolCnt=0
$StencilY = CStr(cdbl($Stencily) - CDbl($StenYSP))
$StencilX = "0.5"
Endif

; Checking to see if the page is full, if the page is full
; If the page is full Creating a new page in the work book and adding the header
If $Stencily=0
; Create a new Page
$=AddPage()
$StencilY="10.00"
EndIf
EndFunction

Function AddPage()
; ******************************************************************************************
; Function Creates on New Visio Page And Adds Header
; ******************************************************************************************
$PageCnt = $PageCnt + 1
$pagsObj = $AppVisio.ActiveDocument.Pages
$Addpage = $PagsObj.Add
$addPage.Name = "$PageDesc-P$Pagecnt"
$pagObj = $pagsObj.Item($PageCnt)
$AppWindow = $AppVisio.ActiveWindow.Page
$Header = $AppWindow.DrawRectangle(0.2, 10.5, 8.2, 10.8)
$Header.TextStyle = "Normal"
$Header.LineStyle = "Text Only"
$Header.FillStyle = "Text Only"
$Header.Text = "$ReportHeader"
EndFunction

Function SSpacing()
$StencilX = "0.5" ; Starting point for the Horizontal Rows
$StencilY = "10.00" ; Starting Point for the veritcal rows
$StenYSp = "0.5" ; Used to determing the Vertical Spacing of the Rows
$StenXSp = "0.75" ; Used to determing the Horizontal Spacing of the Rows
EndFunction

Function ACustomAttributes($Name,$Value,$ShpObjID)
$vsoShape1 = $AppVisio.ActiveWindow.Page.Shapes.ItemFromID($ShpObjID)
$intPropRow2 = $vsoShape1.AddNamedRow(243, $Name, 0)
$PropValue=CStr("Prop.$Name")
$vsoShape1.Cells("Prop." + Cstr($Name) + ".Label").Formula='"$Name"'
$vsoShape1.Cells("Prop." + Cstr($Name) + ".Value").Formula='"$value"'
EndFunction



Once the script runs, click on an Object and Click Shape, Custom proberties to see all details about the object. I will also be creating a Visio report template to use with this script and will post that here once i get it finished.

Screen Shots










Edited by bsockel (2005-12-20 11:11 PM)