SHARE
TWEET

SCOMDrawClassTree.ps1

a guest Apr 3rd, 2013 33 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. param(
  2.         [string[]]$ClassNames,
  3.         [switch]$Help
  4. )
  5.  
  6. if (-not $ClassNames -and -not $help){
  7.         Write-Error "Необходимо указать параметр $ClassNames"
  8.         $Help = $true
  9. }
  10.  
  11. if ($help){
  12.         Write-Host "SCOM MP Class Visualizer script, version 0.1"
  13.         Write-Host "http://gexeg.blogspot.com"
  14.         Write-Host "Параметры: "
  15.         Write-Host "   -Help                    : вывод справочной информации "
  16.         Write-Host "   -ClassNames <[string[]]> : необходимо указать массив классов,"
  17.         Write-Host "                              по которым будет строиться дерево классов`n"
  18.         Write-Host "Примеры использования:"
  19.         Write-Host "1) .\SCOMDrawClassTree.ps1 -ClassNames ""Microsoft.Windows.Server.2008.AD.DomainControllerRole"", ""Microsoft.Windows.Server.2008.AD.DC.KDC"""
  20.         Write-Host "`n2) .\SCOMDrawClassTree.ps1 -ClassNames ""Microsoft.Windows.Server.2008.AD.DomainControllerRole"""
  21.         Write-Host "`n3) `$classNames = Get-SCOMClass -ManagementPack (Get-ScomManagementPack -Name ""Microsoft.Windows.Server.AD.Library"") | foreach {`$_.Name}"
  22.         Write-Host "   .\SCOMDrawClassTree.ps1 -ClassNames `$classNames"
  23.         exit
  24. }
  25.  
  26. if (-not (Get-Module OperationsManager)){
  27.         Import-Module OperationsManager
  28. }
  29.  
  30. [hashtable]$classes = @{}
  31. [hashtable]$shapes = @{}
  32.  
  33. #Const VisSectionIndices
  34. $visSectionObject = 1
  35. $visSectionParagraph = 4
  36. $visSectionProp = 243
  37.  
  38. #Const VisRowIndices
  39. $visRowXFormOut = 1
  40. $visRowTextXForm = 12
  41. $visRowPageLayout = 24
  42. $visRowLast = -2
  43. $visRowFill = 3
  44.  
  45. #Const
  46. $visXFormPinX = 0
  47. $visXFormPinY = 1
  48. $visXFormWidth = 2
  49. $visPLOPlaceStyle = 8
  50. $visPLORouteStyle = 9
  51. $visPLOLineRouteExt = 29
  52. $visCustPropsLabel = 2
  53. $visCustPropsType = 5
  54. $visCustPropsValue = 0
  55. $visFillForegnd = 0
  56. $visFillBkgnd = 1
  57.  
  58. $visTagDefault = 0
  59. $visLayoutIncrSpace = 2
  60. $visLayoutHorzAlignNone = 0
  61. $visLayoutVertAlignNone = 0
  62. $visMillimeters = 70
  63.  
  64.  
  65. function VisioResizeShape($shape){
  66.         $shape.CellsSRC($visSectionObject, $visRowXFormOut, 2).FormulaU = "10 mm"
  67.         $shape.CellsSRC($visSectionObject, $visRowXFormOut, 3).FormulaU = "10 mm"
  68. }
  69.  
  70. function VisioSetConStyle($con){
  71.         $con.CellsSRC($visSectionObject,2,0).FormulaU = "0.25 pt"
  72.         $con.CellsSRC($visSectionObject,23,19).FormulaU = "0"
  73. }
  74.  
  75. function VisioSetText($shape, $text){
  76.         $chars = $shape.Characters
  77.         $chars.Begin = 0
  78.         $chars.Begin = 0
  79.         $chars.Text = $text
  80.  
  81.        
  82.         $shape.CellsSRC($visSectionObject,11,4).FormulaU = "0"
  83.         $shape.CellsSRC($visSectionParagraph,0,6).FormulaU = "0"
  84.        
  85.         $shape.CellsSRC($visSectionObject,$visRowTextXForm,$visXFormWidth).FormulaU = "5"
  86.         $shape.CellsSRC($visSectionObject,$visRowTextXForm,$visXFormPinX).FormulaU = "3"
  87.         #$shape.CellsSRC($visSectionObject,$visRowTextXForm,$visXFormPinY).FormulaU = "Height*0.5"
  88.        
  89.         #$shape.CellsSRC($visSectionObject,$visRowTextXForm, 4).FormulaU = "-1"
  90.     #$shape.CellsSRC($visSectionObject,$visRowTextXForm, 5).FormulaU = "TxtHeight*2"
  91.  
  92. }
  93.  
  94. function VisioAddDataRow($shape, $Name, $Value){
  95.         $row = $shape.AddRow($visSectionProp, $visRowLast, $visTagDefault)
  96.         $shape.CellsSRC($visSectionProp, $row, $visCustPropsLabel).FormulaU = """$Name"""
  97.         $shape.CellsSRC($visSectionProp, $row, $visCustPropsType).FormulaU = "0"
  98.         $shape.CellsSRC($visSectionProp, $row, $visCustPropsValue).FormulaU = """$Value"""
  99. }
  100.  
  101.  
  102.  
  103. function VisioRearIcons(){
  104.         $page.PageSheet.CellsSRC($visSectionObject, $visRowPageLayout, $visPLOPlaceStyle).FormulaForceU = "7"
  105.     $page.PageSheet.CellsSRC($visSectionObject, $visRowPageLayout, $visPLORouteStyle).FormulaForceU = "3"
  106.     $page.Layout()
  107.         $visio.ActiveWindow.SelectAll()
  108.         $visio.ActiveWindow.Selection.LayoutIncremental($visLayoutIncrSpace,
  109.                 $visLayoutHorzAlignNone, $visLayoutVertAlignNone, 70, 8, $visMillimeters)
  110.         $page.Shapes.ItemFromID(0).CellsSRC($visSectionObject, $visRowPageLayout, $visPLOLineRouteExt).FormulaU = "2"
  111. }
  112.  
  113. function PopulateClassTree($ClassID){
  114.         while ($ClassID){
  115.                 $obj = Get-SCOMClass -Id $ClassID
  116.                 if ($obj){
  117.                         $ClassID = $obj.Base.Id
  118.                         $obj | add-member -Name ParentID -MemberType NoteProperty -Value $ClassID
  119.                         $classes[$obj.Id] = $obj
  120.                         if (-not $ClassID){
  121.                                 break
  122.                         }
  123.                 }
  124.         }
  125. }
  126.  
  127. function PopulateAttr($Shape, $ClassObj){
  128.         VisioAddDataRow -shape $Shape -Name "::::::::Class Properties::::" -Value ":::::::::::::::"
  129.         VisioAddDataRow -shape $Shape -Name "Abstract" -Value $classObj.Abstract
  130.         VisioAddDataRow -shape $Shape -Name "Accessibility" -Value $classObj.Accessibility
  131.         VisioAddDataRow -shape $Shape -Name "Extension" -Value $classObj.Extension
  132.         VisioAddDataRow -shape $Shape -Name "Hosted" -Value $classObj.Hosted
  133.         VisioAddDataRow -shape $Shape -Name "Singleton" -Value $classObj.Singleton
  134.         VisioAddDataRow -shape $Shape -Name "Description" -Value $classObj.Description
  135.        
  136.         if ($ClassObj.PropertyCollection.Count -gt 0){
  137.                 VisioAddDataRow -shape $Shape -Name "::::::::Attributes::::" -Value ":::::::::::::::"
  138.                 $ClassObj.PropertyCollection | sort Name | foreach {
  139.                         if ($_.Key -eq $true) { $isKey = "Key" } else { $isKey=$null }
  140.                         if ($_.Required -eq $true) { $Required = "Mandatory" } else { $Required = "Optional"}
  141.                         $propVal = [string]::Join(",", @($_.SystemType, "Min: $($_.MinLength)", "Max: $($_.MaxLength)", $Required, $isKey))
  142.                         VisioAddDataRow -shape $Shape -Name $_.Name -Value $propVal
  143.                 }
  144.         }
  145. }
  146.  
  147. $initVisio = {
  148.         Write-Host "Создание приложения Visio"
  149.         $visio = New-Object -ComObject Visio.Application
  150.         $visio.Visible = $false
  151.         $visio.Documents.Add("BASICD_M.VST") | Out-Null
  152.         $doc = $visio.Documents.Item(1)
  153.         $page = $doc.Pages.Item(1)
  154.         $Stensils = $visio.Documents.Item("BASIC_M.VSS")
  155.         $pentagon = $Stensils.Masters.ItemU("Pentagon")
  156.         $dyncon = $Stensils.Masters.ItemU("Dynamic connector")
  157. }
  158.  
  159. $unInitVisio = {
  160.         $visio.Visible = $true
  161.         Write-Host "Переключитесь в Visio и сохраните сформированный документ."
  162.         $visio.quit()
  163.         $page = $null
  164.         $doc = $null
  165.         $visio = $null
  166. }
  167.  
  168. . $initVisio
  169.  
  170. foreach ($className in $ClassNames){
  171.         Write-Host "Обрабатываем класс $className"
  172.         $classObj = Get-SCOMClass -Name $className
  173.         Write-Host "Заполняем дерево классов"
  174.         PopulateClassTree -ClassID $classObj.ID
  175. }
  176.  
  177. Write-Host "Отрисовка объектов"
  178. $classes.Keys | foreach {
  179.         $shape = $page.Drop($pentagon, 1,1)
  180.         $shape.Name = $classes[$_].Name
  181.        
  182.         if ($classes[$_].Singleton -eq $true){
  183.                 $shape.CellsSRC($visSectionObject, $visRowFill, $visFillBkgnd).FormulaU = "THEMEGUARD(MSOTINT(THEME(""LineColor""),80))"
  184.         }
  185.         elseif ($classes[$_].Abstract -eq $false){
  186.                 $shape.CellsSRC($visSectionObject, $visRowFill, $visFillBkgnd).FormulaU = "THEMEGUARD(MSOTINT(THEME(""AccentColor4""),40))"
  187.         }
  188.        
  189.         VisioResizeShape -shape $shape
  190.         VisioSetText -shape $shape -text ("$($classes[$_].Name)`n$($classes[$_].DisplayName)`n$($classes[$_].ManagementPackName)")
  191.         PopulateAttr -shape $shape -ClassObj $classes[$_]
  192.         $shapes[$_] = $shape
  193. }
  194.  
  195. foreach ($class in $classes.Keys){
  196.         if (-not $classes[$class].ParentID){
  197.                 continue
  198.         }
  199.        
  200.         $con = $page.Drop($dyncon, 1,1)
  201.         $shapeTo = $shapes[$class]
  202.         $shapeFrom = $shapes[$classes[$class].ParentID]
  203.         $con.CellsU("BeginX").GlueTo($shapeFrom.CellsSRC(7,0,0))
  204.         $con.CellsU("EndX").GlueTo($shapeTo.CellsSRC(7,5,0))
  205.         VisioSetConStyle -con $con
  206. }
  207.  
  208. VisioRearIcons
  209. Write-Host "Отрисовка объектов закончена"
  210. . $unInitVisio
RAW Paste Data
Top