Page 1 of 1 1
Topic Options
#153659 - 2005-12-19 05:16 PM AD Network Site Diagram From Kixtart
TexasBrownsFan Offline
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
#153660 - 2005-12-19 07:49 PM Re: AD Network Site Diagram From Kixtart
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Cool
Will give a go on our test AD tomorrow when I'm back at work.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#153661 - 2005-12-19 07:57 PM Re: AD Network Site Diagram From Kixtart
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
If you get a chance to send me that image, will post it asap.

-Shawn

Top
#153662 - 2005-12-19 08:06 PM Re: AD Network Site Diagram From Kixtart
TexasBrownsFan Offline
Fresh Scripter

Registered: 2001-02-07
Posts: 36
Loc: Fort Worth , TX, USA
I will have to run it on my test machine at home, and get that to you. Script pulls to much info to post production information.
Top
#153663 - 2005-12-19 08:30 PM Re: AD Network Site Diagram From Kixtart
TexasBrownsFan Offline
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
#153664 - 2005-12-20 06:48 PM Re: AD Network Site Diagram From Kixtart
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Added images to first post. Will let Author give further details.
Top
#153665 - 2005-12-20 07:58 PM Re: AD Network Site Diagram From Kixtart
Kdyer Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#153666 - 2005-12-20 08:09 PM Re: AD Network Site Diagram From Kixtart
TexasBrownsFan Offline
Fresh Scripter

Registered: 2001-02-07
Posts: 36
Loc: Fort Worth , TX, USA
For Some reason it will not let me make changes to my original post, that is why i had to do another post, i can repost the whole script if you would like or you can wait for the next version.

The next version will be a kix form allowing you to generate a report on all objects with in AD, not just restricted to the sites.

Top
#153667 - 2005-12-20 08:14 PM Re: AD Network Site Diagram From Kixtart
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
hmmm, i edited your post to insert the pictures. not aware of any issues around me doing that ... what kinda error/trouble you having ? If you want to start a new post (maybe you should), feel free to reference the images I inserted ...
Top
#153668 - 2005-12-20 09:07 PM Re: AD Network Site Diagram From Kixtart
Howard Bullock Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#153669 - 2005-12-20 11:22 PM Re: AD Network Site Diagram From Kixtart
TexasBrownsFan Offline
Fresh Scripter

Registered: 2001-02-07
Posts: 36
Loc: Fort Worth , TX, USA
I was not seeing the edit button because i did not scroll over far enough due to the long line, but that is fixed now.

If you have not played with the reporting option with in visio, That generates a nice little report from the diagram and custom properties. You will need to create a custom report selecting which columns that you wnat. But leave off the allowedAttributesEffective Column, it is kind of long.

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.062 seconds in which 0.026 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org