There are many properties of a user account that are neglected and left untouched most of the times, like Description and Manager fields, in the Active Directory domain.
If we enter relevant info into these fields, we can get more information about user; its title, its manager and its direct reports.
On the other hand, it is understandable too not to enter such info because info about users changes frequently so, it must be updated periodically.
But let’s assume we have domain that those info about users entered correctly:
In the above figure, description field shows that there are a CEO, some VPs and Directors. The rest are the soldiers.
And, in addition to the Description field, Manager field for users is entered correctly too, like in the following figure:
Then the following code will create a nice organizational chart:
$list=get-aduser -filter * -Properties * | select name,description,manager #get the users’ name,description and manager properties
New-HTML -OnlIne -FIlePath $PSScrIptRootMyDIagram.html {
New-HTMLDiagram {
New-DiagramOptionsLayout -HierarchicalEnabled $true
New-DiagramOptionsPhysics -Enabled $true -HierarchicalRepulsionAvoidOverlap 1 -HierarchicalRepulsionNodeDistance 100
$list | foreach {
$desc=$_.description
$nameuser=$_.name
switch ($desc){
"ceo" {new-diagramnode -label $nameuser -level 0}
"vp" {new-diagramnode -label $nameuser -level 1}
"director" {new-diagramnode -label $nameuser -level 2}
default {new-diagramnode -label $nameuser -level 3}
}
}
$list | foreach {
$manag=$_.manager -replace "cn=" -replace "ou=" #get rid of cn and ou statements in the manager field
$manag=$manag.substring(0,$manag.indexof(",")) #take upto the first comma
$nameuser=$_.name
new-diagramlink -from $nameuser -to $manag
}
}
}-ShowHTML
Do not forget to install the necessary module first, if you didnot do it before:
Install-Module PSWriteHTML
The chart will be:
Bir Cevap Yazın