MuratYildirimoglu

Creating an Organization Chart Using the Info in Active Directory

May 12th, 2021
19
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Install-Module PSWriteHTML
  2.  
  3. $list=get-aduser -filter * -Properties * | select name,description,manager #get the users’ name,description and manager properties
  4.  
  5. New-HTML -OnlIne -FIlePath $PSScrIptRootMyDIagram.html {
  6.  
  7. New-HTMLDiagram {
  8.  
  9. New-DiagramOptionsLayout -HierarchicalEnabled $true
  10.  
  11. New-DiagramOptionsPhysics -Enabled $true -HierarchicalRepulsionAvoidOverlap 1 -HierarchicalRepulsionNodeDistance 100
  12.  
  13. $list | foreach {
  14.  
  15. $desc=$_.description
  16.  
  17. $nameuser=$_.name
  18.  
  19. switch ($desc){
  20.  
  21. "ceo" {new-diagramnode -label $nameuser -level 0}
  22.  
  23. "vp" {new-diagramnode -label $nameuser -level 1}
  24.  
  25. "director" {new-diagramnode -label $nameuser -level 2}
  26.  
  27. default {new-diagramnode -label $nameuser -level 3}
  28.  
  29. }
  30.  
  31. }
  32.  
  33. $list | foreach {
  34.  
  35. $manag=$_.manager -replace "cn=" -replace "ou=" #Manager alanından cn ve ou ifadelerini kaldırır
  36.  
  37. $manag=$manag.substring(0,$manag.indexof(",")) #ilk virgüle kadarki kısmı alır.
  38.  
  39. $nameuser=$_.name
  40.  
  41. new-diagramlink -from $nameuser -to $manag
  42.  
  43. }
  44.  
  45. }
  46.  
  47. }-ShowHTML
RAW Paste Data