#153659 - 2005-12-19 05:16 PM
AD Network Site Diagram From Kixtart
|
TexasBrownsFan
Fresh Scripter
Registered: 2001-02-07
Posts: 36
Loc: Fort Worth , TX, USA
|
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)
|
Top
|
|
|
|
#153663 - 2005-12-19 08:30 PM
Re: AD Network Site Diagram From Kixtart
|
TexasBrownsFan
Fresh Scripter
Registered: 2001-02-07
Posts: 36
Loc: Fort Worth , TX, USA
|
There is an error in the script in the AddPage() Function. When more then two pages are added to the document, the script continues add object to page two instead of moving to page 3, 4, 5, etc... this fixes the problem Bad Code: Code:
$pagObj = $pagsObj.Item(2)
Working Code $pagObj = $pagsObj.Item($PageCnt)
|
Top
|
|
|
|
#153665 - 2005-12-20 07:58 PM
Re: AD Network Site Diagram From Kixtart
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
This is the coolest script I have seen in quite a while!
To the author, you talk about the error with and needs to be corrected to: Code:
$pagObj = $pagsObj.Item($PageCnt)
Can you please modify your code and put this in place?
You also have some vars in Strings, e.g.: Code:
$stnObj = $AppVisio.Documents("$VSS")
Which can be modified to (and it still works).. Code:
$stnObj = $AppVisio.Documents($VSS)
Lastly, you do have a long line that should taken care of too..
Thanks again!
Kent
|
Top
|
|
|
|
#153668 - 2005-12-20 09:07 PM
Re: AD Network Site Diagram From Kixtart
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
When you post your new script please break long lines into lengths that display properly. The current post is far too wide.
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
1 registered
(Allen)
and 466 anonymous users online.
|
|
|