daily pastebin goal
65%
SHARE
TWEET

SCOM MP Class Visualizer 2.0

a guest Apr 4th, 2013 103 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.2"
  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. function PopulateBaseAttr($shape, $classObj){
  148.         if ($classObj.ParentID){
  149.                 $attribs = @()
  150.                
  151.                 while($classObj.ParentID){
  152.                         $classObj = $classes[$classObj.ParentID]
  153.                         if ($ClassObj.PropertyCollection.Count -gt 0){
  154.                                 VisioAddDataRow -shape $Shape -Name ":::$($ClassObj.Name)::" -Value ":Attributes::::"
  155.                                 $ClassObj.PropertyCollection | sort Name | foreach {
  156.                                 if ($_.Key -eq $true) { $isKey = "Key" } else { $isKey=$null }
  157.                                 if ($_.Required -eq $true) { $Required = "Mandatory" } else { $Required = "Optional"}
  158.                                 $propVal = [string]::Join(",", @($_.SystemType, "Min: $($_.MinLength)", "Max: $($_.MaxLength)", $Required, $isKey))
  159.                                 VisioAddDataRow -shape $Shape -Name $_.Name -Value $propVal
  160.                                 }
  161.                         }
  162.                 }
  163.         }
  164. }
  165.  
  166. $initVisio = {
  167.         Write-Host "Создание приложения Visio"
  168.         $visio = New-Object -ComObject Visio.Application
  169.         $visio.Visible = $false
  170.         $visio.Documents.Add("BASICD_M.VST") | Out-Null
  171.         $doc = $visio.Documents.Item(1)
  172.         $page = $doc.Pages.Item(1)
  173.         $Stensils = $visio.Documents.Item("BASIC_M.VSS")
  174.         $pentagon = $Stensils.Masters.ItemU("Pentagon")
  175.         $dyncon = $Stensils.Masters.ItemU("Dynamic connector")
  176. }
  177.  
  178. $unInitVisio = {
  179.         $visio.Visible = $true
  180.         Write-Host "Переключитесь в Visio и сохраните сформированный документ."
  181.         $visio.quit()
  182.         $page = $null
  183.         $doc = $null
  184.         $visio = $null
  185. }
  186.  
  187. . $initVisio
  188.  
  189. foreach ($className in $ClassNames){
  190.         Write-Host "Обрабатываем класс $className"
  191.         $classObj = Get-SCOMClass -Name $className
  192.         Write-Host "Заполняем дерево классов"
  193.         PopulateClassTree -ClassID $classObj.ID
  194. }
  195.  
  196. Write-Host "Отрисовка объектов"
  197. $classes.Keys | foreach {
  198.         $shape = $page.Drop($pentagon, 1,1)
  199.         $shape.Name = $classes[$_].Name
  200.        
  201.         if ($classes[$_].Singleton -eq $true){
  202.                 $shape.CellsSRC($visSectionObject, $visRowFill, $visFillBkgnd).FormulaU = "THEMEGUARD(MSOTINT(THEME(""LineColor""),80))"
  203.         }
  204.         elseif ($classes[$_].Abstract -eq $false){
  205.                 $shape.CellsSRC($visSectionObject, $visRowFill, $visFillBkgnd).FormulaU = "THEMEGUARD(MSOTINT(THEME(""AccentColor4""),40))"
  206.         }
  207.        
  208.         VisioResizeShape -shape $shape
  209.         VisioSetText -shape $shape -text ("$($classes[$_].Name)`n$($classes[$_].DisplayName)`n$($classes[$_].ManagementPackName)")
  210.         PopulateAttr -shape $shape -ClassObj $classes[$_]
  211.         PopulateBaseAttr -shape $shape -ClassObj $classes[$_]
  212.         $shapes[$_] = $shape
  213. }
  214.  
  215. foreach ($class in $classes.Keys){
  216.         if (-not $classes[$class].ParentID){
  217.                 continue
  218.         }
  219.        
  220.         $con = $page.Drop($dyncon, 1,1)
  221.         $shapeTo = $shapes[$class]
  222.         $shapeFrom = $shapes[$classes[$class].ParentID]
  223.         $con.CellsU("BeginX").GlueTo($shapeFrom.CellsSRC(7,0,0))
  224.         $con.CellsU("EndX").GlueTo($shapeTo.CellsSRC(7,5,0))
  225.         VisioSetConStyle -con $con
  226. }
  227.  
  228. VisioRearIcons
  229. Write-Host "Отрисовка объектов закончена"
  230. . $unInitVisio
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top