PowerShell and Visio – Documenting AD: 1
If we take the concept of our last script that added objects to a drawing we can use this as the basis of a way to automate the documentation of our AD.
One of the first things we need to document is the OU structure. If you have ever produced one of these it is a tedious affair and they are difficult to maintain. So lets automate it.
This is how we create a basic OU structure.
| 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035
| $visio = New-Object -ComObject Visio.Application $docs = $visio.Documents ## use blank drawing $doc = $docs.Add("") ## set active page $pages = $visio.ActiveDocument.Pages $page = $pages.Item(1) ## Add a stencil $mysten = "C:\Program Files\Microsoft Office\Office14\Visio Content\1033\ADO_M.vss" $stencil = $visio.Documents.Add($mysten) ## Add objects $domain = $stencil.Masters.Item("Domain") $ou = $stencil.Masters.Item("Organizational Unit") $dircon = $stencil.Masters.Item("Directory connector") $dom = $page.Drop($domain, 1, 11) $dom.Resize(1, 5, 70) $ou1 = $page.Drop($ou, 1.5, 10.25) $ou1.Resize(1, 5, 70) $ou2 = $page.Drop($ou, 1.5, 9.5) $ou2.Resize(1, 5, 70) $dom_ou1 = $page.Drop($dircon,2,10.25) $start = $dom_ou1.CellsU("BeginX").GlueTo($dom.CellsU("PinX")) $end = $dom_ou1.CellsU("EndX").GlueTo($ou1.CellsU("PinX")) $dom_ou1 = $page.Drop($dircon,2,9.5) $start = $dom_ou1.CellsU("BeginX").GlueTo($dom.CellsU("PinX")) $end = $dom_ou1.CellsU("EndX").GlueTo($ou2.CellsU("PinX")) |
The basic changes from last time are that I’m starting with a blank drawing and adding the Active Directory stencil. Objects are added and resized as before. I’m also using the directory connector object rather than the default connector.
If you look at the positions of the objects you can see that I’m automatically aligning them in vertical columns by defining the X co-ordinate.
This script is OK as an experiment to discover how things work but we usually have a lot more objects than this and the depth of the child OUs needs to be considered. We need to be able to read in the OU data and move some of this activity into functions so we can reuse the code.
That’s the next job.