З початком!

Вітаю Усіх!

В ефірі Андрій Романенко. Я ІТ Архітектор та Інструктор. Моя основна спеціалізація і сфера професійних інтересів – Це Віртуалізація, Хмарні технології, Інфраструктура як Код і усе, що корелює із цією тематикою.

Цей Блог – спроба систематизації, узагальнення і оцифровки усього, що накопичилось у вигляді паперових щоденників, електронних заміток, документів, так і просто раптово прийдешніх думок за останні років так 20-ть. Деякі замітки будуть датовані тим часовим відрізком, коли були написані.

Буду радий, якщо кожен відвідувач знайде тут для себе щось корисне.

С повагою, Андрій.

P.S. Перелік навчальних курсів, котрі я проводжу знаходяться на сторінці Навчання. Контактну інформацію можна глянути на сторінці Про Мене.

Опубліковано в категорії: Загальне | Позначки: , | Залишити коментар

Microsoft System Center Virtual Machine Manager 2007 – Фундамент віртуалізованого центру обробки даних. Частина 2. Архітектура.

Опубліковано в категорії: Microsoft, Віртуалізація, Ретроспектива, Технології | Залишити коментар

Архітектура і Дизайн. Код і Програмування. Частина 3. Вступ. Функції Powershell. PSVisio.ps1. MsSCVMM2k7ArchDiagramV1.ps1. Короткий Підсумок.

 

Вступ


Привіт усім читачам блогу про ІТ Архітектуру і Навчання

Продовжуємо публікацію статей під концептуальною назвою “Архітектура і Дизайн. Впровадження і Експлуатація. Код і Програмування”.

У минулому матеріалі мова йшла про відображення схеми архітектури системи Microsoft System Center Virtual Machine Manager 2007 у форматі Visio для відповідної серії статей. Ми виконали цю роботу за допомогою коду Powershell. Результат повністю задовільнив наші очікування. Проте, основним суттєвим недоліком є об’єм коду і відсутність стратегії повторного його використання. За допомогою функцій можна організувати блоки коду для повторного використання і скоротити його загальний об’єм.

Саме цьому і буде присвячений цей допис.

Функції Powershell


Реалізація роботи функцій Powershell потребує розміщення цього коду у файлі і відповідного синтаксису команд та ініціалізації цих елементів.  Отож, створимо новий файл PSVisio.ps1 у котрому будуть розміщені усі наші напрацювання. 

Для того, щоб виконати ініціалізацію коду написаних нами функцій Powershell слід буде виконати таку команду:

. .\PSVisio.ps1

При внесенні змін у код, слід буде вивантажити змінену функцію командою:

rm Function:\NameOfFunction

І знову виконати ініціалізацію командою, що була описана вище.

На початку нашого написання коду і наповнення функціями файл PSVisio.ps1 буде містити заголовок у вигляді коментарів і початкову ініціалізацію декількох змінних. Вони будуть використані у формуванні імені об’єкта шляхом послідовної нумерації:

#######################################################################
#
# Powershell functions for operate Visio Drawing
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  14.09.2007
# Purpose/Change: Initial script development.
# Create function New-VisioApplication.
#
# Run:
#   
# . .\PSVisio.ps1
#
#######################################################################

# Set Variables
$Shape=0
$Line=0
$Icon=0
$Text=0
$PolyLine=0

New-VisioApplication 

Нагадаємо собі початковий фрагмент коду, котрий ми описали у минулому дописі:

# Step 1.
# Create Visio Object
# Create Document from Blank Template
# Set Active Page
$Application = New-Object -ComObject Visio.Application
$Application.Visible = $True
$Documents = $Application.Documents
$Document=$Application.Documents.Add('')
$Page=$Application.ActivePage
$Application.ActivePage.PageSheet

# Step 2.
# Add Basic Visio Stensils
# Set Masters Item Rectangle
$Stensil1 = $Application.Documents.Add("BASIC_M.vss")
$Rectangle = $Stensil1.Masters.Item("Rectangle")

Як бачимо, він починається із операторів створення Об’єкту застосунку Visio. Оформимо ці нескладні кроки у вигляді першої функції – New-VisioApplication.

Function New-VisioApplication {

#######################################################################
#
# Powershell function for create Visio Application
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  14.09.2007
# Purpose/Change: Initial script development
#
# Run:
#   
# New-VisioApplication
#
#######################################################################

# Create Visio Object
$Script:Application = New-Object -ComObject Visio.Application
$Script:Application.Visible = $True
}

Функція виявилася доволі проста і не передбачає роботи із жодними параметрами. Не забуваємо вносити коментарі із поясненнями до свого коду.

New-VisioDocument

Опишемо наступну функцію для створення нового документа Visio: New-VisioDocument.

Функція створить новий Документ Visio на основі порожнього шаблона. Вхідних параметрів у цієї функції також немає.

Function New-VisioDocument {

#######################################################################
#
# Powershell function for create Visio Document
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  14.09.2007
# Purpose/Change: Initial script development
#
# Run:
#   
# New-VisioDocument
#
#######################################################################

# Create Document from Blank Template
$Script:Documents = $Script:Application.Documents
$Script:Document=$Script:Application.Documents.Add('')
}

Set-VisioPage 

Функція Set-VisioPage також нескладна. ЇЇ логіка у встановленні Активної сторінки, котра буде основою нашої майбутньої схеми. Функція також не має вхідних параметрів.

Function Set-VisioPage {

#######################################################################
#
# Powershell function for Set Active Visio Document Page
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  14.09.2007
# Purpose/Change: Initial script development
#
# Run:
#   
# Set-VisioPage
#
#######################################################################

# Set Visio Active Page
$Script:Page=$Script:Application.ActivePage
$Script:Application.ActivePage.PageSheet
}

Add-VisioStensil

У Visio фігури базуються на основі трафаретів. Тому завдання наступної функції Add-VisioStensil додати трафарети фігур із відповідного файлу .vss. Функція отримує два параметри на вхід: Name – імя для об’єкту трафарета, і File – назва файлу трафаретів.

Function Add-VisioStensil ($Name, $File) {

#######################################################################
#
# Powershell function for Add Visio Stensil
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  15.09.2007
# Purpose/Change: Initial script development
#
# Run:
#   
# Add-VisioStensil -Name "Basic" -File "BASIC_M.vss"
#
#######################################################################

# Set Expression and Add Visio Stensil
$Expression = '$Script:' + $Name + ' = $Script:Application.Documents.Add("' + $File +'")'
Invoke-Expression $Expression
}

Set-VisioStensilMasterItem

Для роботи із конкретною фігурою слід вказати, що буде головним зразком фігури. Логіку цієї операції ми оформимо у вигляді функції Set-VisioStensilMasterItem. Функція має два вхідних параметри: Stensil – назва обєкту трафарета і Item – назва фігури. 

Function Set-VisioStensilMasterItem ($Stensil, $Item) {

#######################################################################
#
# Powershell function for Set Stensil Master Item
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  15.09.2007
# Purpose/Change: Initial script development
#
# Version:        0.2
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  17.09.2007
# Purpose/Change: Reorganize Variables
#
# Run:
#   
# Set-VisioStensilMasterItem -Stensil "Basic" -Item "Rectangle"
#
#######################################################################

# Set Expression And Set Masters Item Rectangle
$ItemWithoutSpace = $Item -replace " ",""
$Expression = '$Script:' + $ItemWithoutSpace + ' = $Script:' + $Stensil + '.Masters.Item("' + $Item + '")'
Invoke-Expression $Expression
}

Draw-VisioItem

Ось ми і підійшли безпосередньо до функцій, котрі будуть виконувати дії зі створення і відображення об’єктів із заданими характеристиками. Для початку це будуть прості геометричні фігури, – прямокутник, коло, лінія, тощо.   

Знову Нагадаємо собі фрагмент коду, що виконує ці дії. 

# Step 3.
# Draw Main Rectangle, Set Size, Set Colour
# Set Text, Size, Color, Align
# Draw Line, Set Weight, Color
$Shape1 = $Page.Drop($Rectangle, 6.375, 7.125)
$Shape1.Cells('Width').Formula = '12.2501'
$Shape1.Cells('Height').Formula = '7.25'
$Shape1.Cells('FillForegnd').Formula = '=RGB(0,153,204)'
$Shape1.Cells('LinePattern').Formula = 0
$Shape1.Text = "Microsoft Virtual Machine Manager Architecture"
$Shape1.Cells('VerticalAlign') = 0
$Shape1.Cells('Para.HorzAlign') = 0
$Shape1.Cells('Char.Size').Formula = '20 pt'
$Shape1.Cells('Char.Color').Formula = '=RGB(255,255,255)'
$Line1 = $Page.DrawLine(0.3125, 10.3438, 12.4948, 10.3438)
$Line1.Cells('LineWeight').Formula = '1 pt'
$Line1.Cells('LineColor').Formula = '=RGB(255,255,255)'

# Step 4.
# Draw Client Rectangle, Set Size, Set Colour
# Set Text, Align
# Draw Line
$Shape2 = $Page.Drop($Rectangle, 1.7656, 9.2344)
$Shape2.Cells('Width').Formula = '2.7813'
$Shape2.Cells('Height').Formula = '1.9688'
$Shape2.Cells('FillForegnd').Formula = '=RGB(209,235,241)'
$Shape2.Cells('LinePattern').Formula = 1
$Shape2.Text = "Client"
$Shape2.Cells('VerticalAlign') = 0
$Shape2.Cells('Char.Size').Formula = '14 pt'
$Line2 = $Page.DrawLine(0.4297, 9.9427, 3.0833, 9.9427)
$Line2.Cells('LineWeight').Formula = '0.5 pt'
$Line2.Cells('LineColor').Formula = '=RGB(0,0,0)'

# Step 5.
# Add Computer Items Visio Stensils
# Set Masters item PC
$Stensil2 = $Application.Documents.Add("COMPS_M.vss")
$PC1 = $Stensil2.Masters.Item("PC")

# Step 6.
# Draw item PC
# Set Text, Size
$Shape3 = $Page.Drop($PC1, 1.1173, 9.1693)
$Shape3.Text = "Administrator Console"
$Shape3.Cells('Char.Size').Formula = '10 pt'

# Step 7.
# Draw Powershell Icon
# Set Position, Size
# Set Text
$Picture1 = $Page.Import("c:\!\powershell.png")
$Picture1.Cells('Width').Formula = '0.9843'
$Picture1.Cells('Height').Formula = '0.9843'
$Picture1.Cells('PinX').Formula = '2.5547'
$Picture1.Cells('PinY').Formula = '9.2682'
$Picture1.Text = "Windows Powershell"
$Picture1.Cells('Char.Size').Formula = '10 pt'

Функція Draw-VisioItem має три обов’язкових параметри: Master – Назву зразка фігури, і координати розташування X та Y. Решта параметрів, такі як: FillForegnd – колір забарвлення фігури, LinePattern – стиль лінії контуру фігури, Text – Текст фігури, VerticalAlign і ParaHorzAlign – парметри вирівнювання тексту по вертикалі і горизонталі, CharSize і CharColor – розмір і колір символів надпису є необовязковими. 

Function Draw-VisioItem ($Master, $X, $Y, $Width, $Height, $FillForegnd, $LinePattern, $Text, $VerticalAlign, $ParaHorzAlign, $CharSize, $CharColor) {

#######################################################################
#
# Powershell function for Draw Visio Item
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  15.09.2007
# Purpose/Change: Initial script development
#
# Version:        0.2
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  16.09.2007
# Purpose/Change: Add Flow Control Input Parameters
#
# Version:        0.3
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  17.09.2007
# Purpose/Change: Reorganize Variables
#
# Run:
#   
# Draw-VisioItem -Master "Rectangle" -X 6.375 -Y 7.125 -Width 12.2501 -Height 7.25 -FillForegnd "RGB(0,153,204)"`
# -LinePattern 0 -Text "Microsoft Virtual Machine Manager Architecture" -VerticalAlign 0 -ParaHorzAlign 0`
# -CharSize "20 pt" -CharColor "RGB(255,255,255)"
#
#######################################################################

$Script:Shape++
$Master = $Master -replace " ",""

# Set Expression And Draw Item
$Expression = '$Script:Shape' + $Script:Shape + ' = $Script:Page.Drop(' + '$' + $Master + ',' + $X + ',' + $Y + ')'
Invoke-Expression $Expression

# Set Item Width Properties
If ($Width)
	{
		$Expression = '$Script:Shape' + $Script:Shape + '.Cells("Width").Formula = ' + $Width
		Invoke-Expression $Expression
	}

# Set Item Height Properties
If ($Height)
	{
		$Expression = '$Script:Shape' + $Script:Shape + '.Cells("Height").Formula = ' + $Height
		Invoke-Expression $Expression
	}

# Set Item FillForegnd Properties
If ($FillForegnd)
	{
		$Expression = '$Script:Shape' + $Script:Shape + '.Cells("FillForegnd").Formula = "=' +  $FillForegnd + '"'
		Invoke-Expression $Expression
	}

# Set Item LinePattern Properties
If ($LinePattern)
	{
		$Expression = '$Script:Shape' + $Script:Shape + '.Cells("LinePattern").Formula = ' + $LinePattern
		Invoke-Expression $Expression
	}

# Set Item Text
If ($Text)
	{
		$Expression = '$Script:Shape' + $Script:Shape + '.Text = "' + $Text + '"'
		Invoke-Expression $Expression
	}

# Set Item VerticalAlign Properties
If ($VerticalAlign)
	{
		$Expression = '$Script:Shape' + $Script:Shape + '.Cells("VerticalAlign").Formula = ' + $VerticalAlign
		Invoke-Expression $Expression
	}

# Set Item HorzAlign Properties
If ($ParaHorzAlign)
	{
		$Expression = '$Script:Shape' + $Script:Shape + '.Cells("Para.HorzAlign").Formula = ' + $ParaHorzAlign
		Invoke-Expression $Expression
	}

# Set Item Char.Size Properties
If ($CharSize)
	{
		$Expression = '$Script:Shape' + $Script:Shape + '.Cells("Char.Size").Formula = "' + $CharSize + '"'
		Invoke-Expression $Expression
	}

# Set Item Char.Color Properties
If ($CharColor)
	{
		$Expression = '$Script:Shape' + $Script:Shape + '.Cells("Char.Color").Formula = "=' +  $CharColor + '"'
		Invoke-Expression $Expression
	}
}

Draw-VisioLine

Функція Draw-VisioLine розроблена для малювання різноманітних ліній. Вона має кілька обовязкових параметри: координати початку BeginXBeginY, і закінчення EndXEndY. Також можуть бути вказані необовязкові параметри: LineColor – колір лінії і стиль стрілок BeginArrowEndArrow

Function Draw-VisioLine ($BeginX, $BeginY, $EndX, $EndY, $LineWeight, $LineColor, $BeginArrow, $EndArrow) {

#######################################################################
#
# Powershell function for Draw Visio Line
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  15.09.2007
# Purpose/Change: Initial script development
#
# Version:        0.2
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  17.09.2007
# Purpose/Change: Add Flow Control Input Parameters
#
# Run:
#   
# Draw-VisioLine -BeginX 0.3125 -BeginY 10.3438 -EndX 12.4948 -EndY 10.3438 -LineWeight "1 pt"`
# -LineColor "RGB(255,255,255)" -BeginArrow 4 -EndArrow 4
#
#######################################################################

$Script:Line++

# Set Expression And Draw Line
$Expression = '$Script:Line' + $Script:Line + ' = $Script:Page.DrawLine(' + $BeginX + ',' + $BeginY + ',' + $EndX + ',' + $EndY + ')'
Invoke-Expression $Expression

# Set Line Width Properties
If ($LineWeight)
	{
		$Expression = '$Script:Line' + $Script:Line + '.Cells("LineWeight").Formula = "' + $LineWeight + '"'
		Invoke-Expression $Expression
	}

# Set Line Color Properties
$Expression = '$Script:Line' + $Script:Line + '.Cells("LineColor").Formula = "=' +  $LineColor + '"'
Invoke-Expression $Expression

# Set Line Begin Arrow Properties
If ($BeginArrow)
	{
		$Expression = '$Script:Line' + $Script:Line + '.Cells("BeginArrow").Formula = ' + $BeginArrow
		Invoke-Expression $Expression
	}

# Set Line End Arrow Properties
If ($EndArrow)
	{
		$Expression = '$Script:Line' + $Script:Line + '.Cells("EndArrow").Formula = ' + $EndArrow
		Invoke-Expression $Expression
	}
}

Draw-VisioIcon

Функція Draw-VisioIcon дасть можливість додавати до схем попередньо підготовлені піктограми у форматі .png чи .jpeg. Вона має кілька обовязкових параметрів: IconPath – шлях і назва файлу піктограми, розміри WidthHeight  і координати PinXPinY. Необовязковими параметрами є текст надпису Text і його розмір символів CharSize

Function Draw-VisioIcon ($IconPath, $Width, $Height, $PinX, $PinY, $Text, $CharSize) {

#######################################################################
#
# Powershell function for Draw Visio Icon
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  16.09.2007
# Purpose/Change: Initial script development
#
# Version:        0.2
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  17.09.2007
# Purpose/Change: Add Flow Control Input Parameters
#
# Run:
#   
# Draw-VisioIcon -IconPath "c:\!\powershell.png" -Width 0.9843 -Height 0.9843 -PinX 2.5547 -PinY 9.2682`
# -Text "Windows Powershell" -CharSize "10 pt"
#
#######################################################################

$Script:Icon++

# Import Icon Item
$Expression = '$Script:Icon' + $Script:Icon + ' = $Script:Page.Import("' + $IconPath + '")'
Invoke-Expression $Expression

# Set Icon Width Properties
$Expression = '$Script:Icon' + $Script:Icon + '.Cells("Width").Formula = ' + $Width
Invoke-Expression $Expression

# Set Icon Height Properties
$Expression = '$Script:Icon' + $Script:Icon + '.Cells("Height").Formula = ' + $Height
Invoke-Expression $Expression

# Set Icon PinX Properties
$Expression = '$Script:Icon' + $Script:Icon + '.Cells("PinX").Formula = ' + $PinX
Invoke-Expression $Expression

# Set Icon PinY Properties
$Expression = '$Script:Icon' + $Script:Icon + '.Cells("PinY").Formula = ' + $PinY
Invoke-Expression $Expression

# Set Icon Text
If ($Text)
	{
		$Expression = '$Script:Icon' + $Script:Icon + '.Text = "' + $Text + '"'
		Invoke-Expression $Expression
	}

# Set Icon Char.Size Properties
If ($CharSize)
	{
		$Expression = '$Script:Icon' + $Script:Icon + '.Cells("Char.Size").Formula = "' + $CharSize + '"'
		Invoke-Expression $Expression
	}
}

Resize-VisioPageToFitContents

Функція Resize-VisioPageToFitContents надзвичайно проста, її завдання виконати зміну розмірів сторінки до розмірів малюнку. Вхідних параметрів вона не має. 

Function Resize-VisioPageToFitContents {

#######################################################################
#
# Powershell function for Resize Active Visio Document Page to Fit Contents
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  17.09.2007
# Purpose/Change: Initial script development
#
# Run:
#   
# Resize-VisioPageToFitContents
#
#######################################################################

# Resize Page to Fit Contents
$Script:Page.ResizeToFitContents()
}

Save-VisioDocument

Залишаються дрібні фінальні кроки. Логіка функції Save-VisioDocument виконати збереження сформованої діаграми у вигляді файлу Visio .vsd. Функція має обовязковий параметер File – назва файлу Visio .vsd. 

Function Save-VisioDocument ($File) {

#######################################################################
#
# Powershell function for save Visio Document
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  17.09.2007
# Purpose/Change: Initial script development
#
# Run:
#   
# Save-VisioDocument -File 'C:\!\MsSCVMM2007Arch.vsd'
#
#######################################################################

# Save Document
$Expression = '$Script:Document.SaveAs("' + $File + '")'
Invoke-Expression $Expression
}

Close-VisioApplication 

Завершує цю сюжетну лінію функція Close-VisioApplication. Вона не має параметрів, іі логіка лише у закритті додатку Visio. 

Function Close-VisioApplication {

#######################################################################
#
# Powershell function for create Visio Application
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  17.09.2007
# Purpose/Change: Initial script development
#
# Run:
#   
# Close-VisioApplication
#
#######################################################################

# Close Visio Application
$Script:Application.Quit()
}

PSVisio.ps1


Фінальний результат коду коду функцій у файлі PSVisio.ps1 виглядає так: 

#######################################################################
#
# Powershell functions for operate Visio Drawing
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  14.09.2007
# Purpose/Change: Initial script development.
# Create function New-VisioApplication.
#
# Version:        0.2
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Change Date:    14.09.2007
# Purpose/Change: Create function New-VisioDocument.
#
# Version:        0.3
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Change Date:    14.09.2007
# Purpose/Change: Create function Set-VisioPage.
#
# Version:        0.4
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Change Date:    15.09.2007
# Purpose/Change: Create function Add-VisioStensil.
#
# Version:        0.5
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Change Date:    15.09.2007
# Purpose/Change: Create function Set-VisioStensilMasterItem.
#
# Version:        0.6
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Change Date:    15.09.2007
# Purpose/Change: Create function Draw-VisioItem.
#
# Version:        0.7
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Change Date:    15.09.2007
# Purpose/Change: Create function Draw-VisioLine.
#
# Version:        0.8
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  16.09.2007
# Purpose/Change: Change function Draw-VisioItem.
#
# Version:        0.9
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Change Date:    16.09.2007
# Purpose/Change: Create function Draw-VisioIcon.
#
# Version:        0.10
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Change Date:    17.09.2007
# Purpose/Change: Change function Draw-VisioIcon.
#
# Version:        0.11
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Change Date:    17.09.2007
# Purpose/Change: Change function Draw-VisioLine.
#
# Version:        0.12
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Change Date:    17.09.2007
# Purpose/Change: Change function Set-VisioStensilMasterItem.
#
# Version:        0.13
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Change Date:    17.09.2007
# Purpose/Change: Change function Draw-VisioItem.
#
# Version:        0.14
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Change Date:    17.09.2007
# Purpose/Change: Add function Resize-VisioPageToFitContents.
#
# Version:        0.15
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Change Date:    17.09.2007
# Purpose/Change: Add function Save-VisioDocument.
#
#
# Version:        0.16
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Change Date:    18.09.2007
# Purpose/Change: Add function Draw-VisioText.
#
# Version:        0.17
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Change Date:    18.09.2007
# Purpose/Change: Add function Draw-VisioPolyLine.
#
# Version:        0.18
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Change Date:    19.09.2007
# Purpose/Change: Change function Draw-VisioText.
#
# Run:
#   
# . .\PSVisio.ps1
#
#######################################################################

# Set Variables
$Shape=0
$Line=0
$Icon=0
$Text=0
$PolyLine=0

Function New-VisioApplication {

#######################################################################
#
# Powershell function for create Visio Application
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  14.09.2007
# Purpose/Change: Initial script development
#
# Run:
#   
# New-VisioApplication
#
#######################################################################

# Create Visio Object
$Script:Application = New-Object -ComObject Visio.Application
$Script:Application.Visible = $True
}

Function New-VisioDocument {

#######################################################################
#
# Powershell function for create Visio Document
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  14.09.2007
# Purpose/Change: Initial script development
#
# Run:
#   
# New-VisioDocument
#
#######################################################################

# Create Document from Blank Template
$Script:Documents = $Script:Application.Documents
$Script:Document=$Script:Application.Documents.Add('')
}

Function Set-VisioPage {

#######################################################################
#
# Powershell function for Set Active Visio Document Page
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  14.09.2007
# Purpose/Change: Initial script development
#
# Run:
#   
# Set-VisioPage
#
#######################################################################

# Set Visio Active Page
$Script:Page=$Script:Application.ActivePage
$Script:Application.ActivePage.PageSheet
}

Function Add-VisioStensil ($Name, $File) {

#######################################################################
#
# Powershell function for Add Visio Stensil
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  15.09.2007
# Purpose/Change: Initial script development
#
# Run:
#   
# Add-VisioStensil -Name "Basic" -File "BASIC_M.vss"
#
#######################################################################

# Set Expression and Add Visio Stensil
$Expression = '$Script:' + $Name + ' = $Script:Application.Documents.Add("' + $File +'")'
Invoke-Expression $Expression
}

Function Set-VisioStensilMasterItem ($Stensil, $Item) {

#######################################################################
#
# Powershell function for Set Stensil Master Item
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  15.09.2007
# Purpose/Change: Initial script development
#
# Version:        0.2
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  17.09.2007
# Purpose/Change: Reorganize Variables
#
# Run:
#   
# Set-VisioStensilMasterItem -Stensil "Basic" -Item "Rectangle"
#
#######################################################################

# Set Expression And Set Masters Item Rectangle
$ItemWithoutSpace = $Item -replace " ",""
$Expression = '$Script:' + $ItemWithoutSpace + ' = $Script:' + $Stensil + '.Masters.Item("' + $Item + '")'
Invoke-Expression $Expression
}

Function Draw-VisioItem ($Master, $X, $Y, $Width, $Height, $FillForegnd, $LinePattern, $Text, $VerticalAlign, $ParaHorzAlign, $CharSize, $CharColor) {

#######################################################################
#
# Powershell function for Draw Visio Item
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  15.09.2007
# Purpose/Change: Initial script development
#
# Version:        0.2
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  16.09.2007
# Purpose/Change: Add Flow Control Input Parameters
#
# Version:        0.3
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  17.09.2007
# Purpose/Change: Reorganize Variables
#
# Run:
#   
# Draw-VisioItem -Master "Rectangle" -X 6.375 -Y 7.125 -Width 12.2501 -Height 7.25 -FillForegnd "RGB(0,153,204)"`
# -LinePattern 0 -Text "Microsoft Virtual Machine Manager Architecture" -VerticalAlign 0 -ParaHorzAlign 0`
# -CharSize "20 pt" -CharColor "RGB(255,255,255)"
#
#######################################################################

$Script:Shape++
$Master = $Master -replace " ",""

# Set Expression And Draw Item
$Expression = '$Script:Shape' + $Script:Shape + ' = $Script:Page.Drop(' + '$' + $Master + ',' + $X + ',' + $Y + ')'
Invoke-Expression $Expression

# Set Item Width Properties
If ($Width)
	{
		$Expression = '$Script:Shape' + $Script:Shape + '.Cells("Width").Formula = ' + $Width
		Invoke-Expression $Expression
	}

# Set Item Height Properties
If ($Height)
	{
		$Expression = '$Script:Shape' + $Script:Shape + '.Cells("Height").Formula = ' + $Height
		Invoke-Expression $Expression
	}

# Set Item FillForegnd Properties
If ($FillForegnd)
	{
		$Expression = '$Script:Shape' + $Script:Shape + '.Cells("FillForegnd").Formula = "=' +  $FillForegnd + '"'
		Invoke-Expression $Expression
	}

# Set Item LinePattern Properties
If ($LinePattern)
	{
		$Expression = '$Script:Shape' + $Script:Shape + '.Cells("LinePattern").Formula = ' + $LinePattern
		Invoke-Expression $Expression
	}

# Set Item Text
If ($Text)
	{
		$Expression = '$Script:Shape' + $Script:Shape + '.Text = "' + $Text + '"'
		Invoke-Expression $Expression
	}

# Set Item VerticalAlign Properties
If ($VerticalAlign)
	{
		$Expression = '$Script:Shape' + $Script:Shape + '.Cells("VerticalAlign").Formula = ' + $VerticalAlign
		Invoke-Expression $Expression
	}

# Set Item HorzAlign Properties
If ($ParaHorzAlign)
	{
		$Expression = '$Script:Shape' + $Script:Shape + '.Cells("Para.HorzAlign").Formula = ' + $ParaHorzAlign
		Invoke-Expression $Expression
	}

# Set Item Char.Size Properties
If ($CharSize)
	{
		$Expression = '$Script:Shape' + $Script:Shape + '.Cells("Char.Size").Formula = "' + $CharSize + '"'
		Invoke-Expression $Expression
	}

# Set Item Char.Color Properties
If ($CharColor)
	{
		$Expression = '$Script:Shape' + $Script:Shape + '.Cells("Char.Color").Formula = "=' +  $CharColor + '"'
		Invoke-Expression $Expression
	}
}

Function Draw-VisioLine ($BeginX, $BeginY, $EndX, $EndY, $LineWeight, $LineColor, $BeginArrow, $EndArrow) {

#######################################################################
#
# Powershell function for Draw Visio Line
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  15.09.2007
# Purpose/Change: Initial script development
#
# Version:        0.2
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  17.09.2007
# Purpose/Change: Add Flow Control Input Parameters
#
# Run:
#   
# Draw-VisioLine -BeginX 0.3125 -BeginY 10.3438 -EndX 12.4948 -EndY 10.3438 -LineWeight "1 pt"`
# -LineColor "RGB(255,255,255)" -BeginArrow 4 -EndArrow 4
#
#######################################################################

$Script:Line++

# Set Expression And Draw Line
$Expression = '$Script:Line' + $Script:Line + ' = $Script:Page.DrawLine(' + $BeginX + ',' + $BeginY + ',' + $EndX + ',' + $EndY + ')'
Invoke-Expression $Expression

# Set Line Width Properties
If ($LineWeight)
	{
		$Expression = '$Script:Line' + $Script:Line + '.Cells("LineWeight").Formula = "' + $LineWeight + '"'
		Invoke-Expression $Expression
	}

# Set Line Color Properties
$Expression = '$Script:Line' + $Script:Line + '.Cells("LineColor").Formula = "=' +  $LineColor + '"'
Invoke-Expression $Expression

# Set Line Begin Arrow Properties
If ($BeginArrow)
	{
		$Expression = '$Script:Line' + $Script:Line + '.Cells("BeginArrow").Formula = ' + $BeginArrow
		Invoke-Expression $Expression
	}

# Set Line End Arrow Properties
If ($EndArrow)
	{
		$Expression = '$Script:Line' + $Script:Line + '.Cells("EndArrow").Formula = ' + $EndArrow
		Invoke-Expression $Expression
	}
}

Function Draw-VisioIcon ($IconPath, $Width, $Height, $PinX, $PinY, $Text, $CharSize) {

#######################################################################
#
# Powershell function for Draw Visio Icon
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  16.09.2007
# Purpose/Change: Initial script development
#
# Version:        0.2
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  17.09.2007
# Purpose/Change: Add Flow Control Input Parameters
#
# Run:
#   
# Draw-VisioIcon -IconPath "c:\!\powershell.png" -Width 0.9843 -Height 0.9843 -PinX 2.5547 -PinY 9.2682`
# -Text "Windows Powershell" -CharSize "10 pt"
#
#######################################################################

$Script:Icon++

# Import Icon Item
$Expression = '$Script:Icon' + $Script:Icon + ' = $Script:Page.Import("' + $IconPath + '")'
Invoke-Expression $Expression

# Set Icon Width Properties
$Expression = '$Script:Icon' + $Script:Icon + '.Cells("Width").Formula = ' + $Width
Invoke-Expression $Expression

# Set Icon Height Properties
$Expression = '$Script:Icon' + $Script:Icon + '.Cells("Height").Formula = ' + $Height
Invoke-Expression $Expression

# Set Icon PinX Properties
$Expression = '$Script:Icon' + $Script:Icon + '.Cells("PinX").Formula = ' + $PinX
Invoke-Expression $Expression

# Set Icon PinY Properties
$Expression = '$Script:Icon' + $Script:Icon + '.Cells("PinY").Formula = ' + $PinY
Invoke-Expression $Expression

# Set Icon Text
If ($Text)
	{
		$Expression = '$Script:Icon' + $Script:Icon + '.Text = "' + $Text + '"'
		Invoke-Expression $Expression
	}

# Set Icon Char.Size Properties
If ($CharSize)
	{
		$Expression = '$Script:Icon' + $Script:Icon + '.Cells("Char.Size").Formula = "' + $CharSize + '"'
		Invoke-Expression $Expression
	}
}

Function Resize-VisioPageToFitContents {

#######################################################################
#
# Powershell function for Resize Active Visio Document Page to Fit Contents
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  17.09.2007
# Purpose/Change: Initial script development
#
# Run:
#   
# Resize-VisioPageToFitContents
#
#######################################################################

# Resize Page to Fit Contents
$Script:Page.ResizeToFitContents()
}

Function Save-VisioDocument ($File) {

#######################################################################
#
# Powershell function for save Visio Document
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  17.09.2007
# Purpose/Change: Initial script development
#
# Run:
#   
# Save-VisioDocument -File 'C:\!\MsSCVMM2007Arch.vsd'
#
#######################################################################

# Save Document
$Expression = '$Script:Document.SaveAs("' + $File + '")'
Invoke-Expression $Expression
}

Function Close-VisioApplication {

#######################################################################
#
# Powershell function for create Visio Application
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  17.09.2007
# Purpose/Change: Initial script development
#
# Run:
#   
# Close-VisioApplication
#
#######################################################################

# Close Visio Application
$Script:Application.Quit()
}

Function Draw-VisioText ($X, $Y, $Width, $Height, $FillForegnd, $LinePattern, $Text, $VerticalAlign, $ParaHorzAlign, $CharSize, $CharColor, $CharStyle, $FillForegndTrans) {

#######################################################################
#
# Powershell function for Draw Visio Text Label
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  18.09.2007
# Purpose/Change: Initial script development
#
# Version:        0.2
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  19.09.2007
# Purpose/Change: Add CharStyle Parameter
#
# Run:
#   
# Draw-VisioText -X 4.25 -Y 8.875 -Width 1.3751 -Height 0.375 -Text "Microsoft Virtual Machine Manager Architecture"`
# -LinePattern "0" -FillForegndTrans "100%" -CharStyle 17
#
#######################################################################

$Script:Text++
$Master = "Rectangle"

# Set Expression And Draw Text
$Expression = '$Script:Text' + $Script:Text + ' = $Script:Page.Drop(' + '$' + $Master + ',' + $X + ',' + $Y + ')'
Invoke-Expression $Expression

# Set Item Width Properties
If ($Width)
	{
		$Expression = '$Script:Text' + $Script:Text + '.Cells("Width").Formula = ' + $Width
		Invoke-Expression $Expression
	}

# Set Item Height Properties
If ($Height)
	{
		$Expression = '$Script:Text' + $Script:Text + '.Cells("Height").Formula = ' + $Height
		Invoke-Expression $Expression
	}

# Set Item FillForegnd Properties
If ($FillForegnd)
	{
		$Expression = '$Script:Text' + $Script:Text + '.Cells("FillForegnd").Formula = "=' +  $FillForegnd + '"'
		Invoke-Expression $Expression
	}

# Set Item LinePattern Properties
If ($LinePattern)
	{
		$Expression = '$Script:Text' + $Script:Text + '.Cells("LinePattern").Formula = ' + $LinePattern
		Invoke-Expression $Expression
	}

# Set Item Text
If ($Text)
	{
		$Expression = '$Script:Text' + $Script:Text + '.Text = "' + $Text + '"'
		Invoke-Expression $Expression
	}

# Set Item VerticalAlign Properties
If ($VerticalAlign)
	{
		$Expression = '$Script:Text' + $Script:Text + '.Cells("VerticalAlign").Formula = ' + $VerticalAlign
		Invoke-Expression $Expression
	}

# Set Item HorzAlign Properties
If ($ParaHorzAlign)
	{
		$Expression = '$Script:Text' + $Script:Text + '.Cells("Para.HorzAlign").Formula = ' + $ParaHorzAlign
		Invoke-Expression $Expression
	}

# Set Item Char.Size Properties
If ($CharSize)
	{
		$Expression = '$Script:Text' + $Script:Text + '.Cells("Char.Size").Formula = "' + $CharSize + '"'
		Invoke-Expression $Expression
	}

# Set Item Char.Color Properties
If ($CharColor)
	{
		$Expression = '$Script:Text' + $Script:Text + '.Cells("Char.Color").Formula = "=' +  $CharColor + '"'
		Invoke-Expression $Expression
	}
	
# Set Item Char.Style Properties
If ($CharStyle)
	{
		$Expression = '$Script:Text' + $Script:Text + '.Cells("Char.Style").Formula = "' + $CharStyle + '"'
		Invoke-Expression $Expression
	}
	
# Set Item FillForegndTrans Properties
If ($FillForegndTrans)
	{
		$Expression = '$Script:Text' + $Script:Text + '.Cells("FillForegndTrans").Formula = "' + $FillForegndTrans + '"'
		Invoke-Expression $Expression
	}		
}

Function Draw-VisioPolyLine ($PolyLine, $LineWeight, $LineColor, $BeginArrow, $EndArrow) {

#######################################################################
#
# Powershell function for Draw Visio PolyLine
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  18.09.2007
# Purpose/Change: Initial script development
#
# Run:
#   
# Draw-VisioPolyLine -Polyline 1.0938,9.0625,1.4063,9.0625,1.4063,8.6563,1.0938,8.6563 -LineWeight "0.5 pt"`
# -LineColor "RGB(255,255,255)" -BeginArrow 1 -EndArrow 1
#
#######################################################################

$Script:PolyLine++
[double[]]$PolyLineCoordinates=@()
$PolyLineCoordinates += $Polyline

# Set Expression And Draw PolyLine
$Expression = '$Script:PolyLine' + $Script:PolyLine + ' = $Script:Page.DrawPolyLine(($PolyLineCoordinates),0)'
Invoke-Expression $Expression

# Set Line Width Properties
If ($LineWeight)
	{
		$Expression = '$Script:PolyLine' + $Script:PolyLine + '.Cells("LineWeight").Formula = "' + $LineWeight + '"'
		Invoke-Expression $Expression
	}

# Set Line Color Properties
$Expression = '$Script:PolyLine' + $Script:PolyLine + '.Cells("LineColor").Formula = "=' +  $LineColor + '"'
Invoke-Expression $Expression

# Set Line Begin Arrow Properties
If ($BeginArrow)
	{
		$Expression = '$Script:PolyLine' + $Script:PolyLine + '.Cells("BeginArrow").Formula = ' + $BeginArrow
		Invoke-Expression $Expression
	}

# Set Line End Arrow Properties
If ($EndArrow)
	{
		$Expression = '$Script:PolyLine' + $Script:PolyLine + '.Cells("EndArrow").Formula = ' + $EndArrow
		Invoke-Expression $Expression
	}
}

Поточна версія вищезазначеного коду знаходиться в репозиторії Git за цим посиланням: PSVisio.ps1.

MsSCVMM2k7ArchDiagramV1.ps1


Відповідно код формування діаграми архітектури системи Microsoft System Center Virtual Machine Manager 2007 у форматі Visio: 

. .\PSVisio.ps1

# Step 1.
# Create Visio Application
# Create Document from Blank Template
# Set Active Page
New-VisioApplication
New-VisioDocument
Set-VisioPage

# Step 2.
# Add Basic Visio Stensils
# Set Masters Item Rectangle
Add-VisioStensil -Name "Basic" -File "BASIC_M.vss"
Set-VisioStensilMasterItem -Stensil Basic -Item "Rectangle"

# Step 3.
# Draw Main Rectangle, Set Size, Set Colour
# Set Text, Size, Color, Align
# Draw Line, Set Weight, Color
Draw-VisioItem -Master "Rectangle" -X 6.375 -Y 7.125 -Width 12.2501 -Height 7.25 -FillForegnd "RGB(0,153,204)"`
 -LinePattern 0 -Text "Microsoft Virtual Machine Manager Architecture" -VerticalAlign '0' -ParaHorzAlign '0'`
 -CharSize "20 pt" -CharColor "RGB(255,255,255)"
Draw-VisioLine -BeginX 0.3125 -BeginY 10.3438 -EndX 12.4948 -EndY 10.3438 -LineWeight "1 pt" -LineColor "RGB(255,255,255)"
 
# Step 4.
# Draw Client Rectangle, Set Size, Set Colour
# Set Text, Align
# Draw Line
Draw-VisioItem -Master "Rectangle" -X 1.7656 -Y 9.2344 -Width 2.7813 -Height 1.9688 -FillForegnd "RGB(209,235,241)"`
 -LinePattern 1 -Text "Client" -VerticalAlign '0' -ParaHorzAlign '1'`
 -CharSize "14 pt" -CharColor "RGB(0,0,0)"
Draw-VisioLine -BeginX 0.4297 -BeginY 9.9427 -EndX 3.0833 -EndY 9.9427 -LineWeight "0.5 pt" -LineColor "RGB(0,0,0)"

# Step 5.
# Add Computer Items Visio Stensils
# Set Masters item PC
Add-VisioStensil -Name "Computer" -File "COMPS_M.vss"
Set-VisioStensilMasterItem -Stensil "Computer" -Item "PC"

# Step 6.
# Draw item PC
# Set Text, Size
Draw-VisioItem -Master "PC" -X 1.1173 -Y 9.1693 -Text "Administrator Console" -CharSize "10 pt"

# Step 7.
# Draw Powershell Icon
# Set Position, Size
# Set Text
Draw-VisioIcon -IconPath "c:\!\powershell.png" -Width 0.9843 -Height 0.9843 -PinX 2.5547 -PinY 9.2682 `
 -Text "Windows Powershell" -CharSize "10 pt"

# Step 8.
# Draw WCF Rectangle, Set Size, Set Colour
# Set Text, Align
# Draw Line
Draw-VisioItem -Master "Rectangle" -X 4.2682 -Y 6.9063 -Width 1.5 -Height 6.625 -FillForegnd "RGB(255,255,255)"`
 -LinePattern 1 -Text "Windows Communication Foundation" -VerticalAlign '0'`
 -CharSize "14 pt"
Draw-VisioLine -BeginX 3.5664 -BeginY 9.4063 -EndX 4.9492 -EndY 9.4063 -LineWeight "0.5 pt" -LineColor "RGB(0,0,0)"

# Step 9.----
# Draw WCF Icon
# Set Position, Size
Draw-VisioIcon -IconPath "c:\!\WCF.png" -Width 1.412 -Height 1.0443 -PinX 4.2708 -PinY 6.9779

# Step 10.
# Draw Line communication from Client to WCF
# Set Arrow
Draw-VisioLine -BeginX 3.1563 -BeginY 9.2396 -EndX 3.5174 -EndY 9.2396 -LineColor "RGB(255,255,255)" -BeginArrow 4 -EndArrow 4

# Step 11.
# Draw Web Client Rectangle, Set Size, Set Colour
# Set Text, Align
# Draw Line
Draw-VisioItem -Master "Rectangle" -X 1.7656 -Y 6.8776 -Width 2.7813 -Height 2.1094 -FillForegnd "RGB(209,235,241)"`
 -LinePattern 1 -Text "Web Client" -VerticalAlign '0'`
 -CharSize "14 pt"
Draw-VisioLine -BeginX 0.4297 -BeginY 7.6562 -EndX 3.0833 -EndY 7.6562 -LineWeight "0.5 pt" -LineColor "RGB(0,0,0)"

# Step 12.
# Draw Self Service Portal Icon
# Set Position, Size
# Set Text
Draw-VisioIcon -IconPath "c:\!\SelfServicePortal.png" -Width 0.8438 -Height 0.8438 -PinX 1.1094 -PinY 6.9271 `
 -Text "Self Service Portal" -CharSize "10 pt"

# Step 13.
# Draw Powershell Icon
# Set Position, Size
# Set Text
Draw-VisioIcon -IconPath "c:\!\powershell.png" -Width 0.9843 -Height 0.9843 -PinX 2.4922 -PinY 6.9192 `
 -Text "Windows Powershell" -CharSize "10 pt"

# Step 14.
# Draw Line communication from Web Client to WCF
# Set Arrow
Draw-VisioLine -BeginX 3.158 -BeginY 6.8802 -EndX 3.5191 -EndY 6.8802 -LineColor "RGB(255,255,255)" -BeginArrow 4 -EndArrow 4

# Step 15.
# Draw Scripting Client Rectangle, Set Size, Set Colour
# Set Text, Align
# Draw Line
Draw-VisioItem -Master "Rectangle" -X 1.7657 -Y 4.5469 -Width 2.7813 -Height 1.9062 -FillForegnd "RGB(209,235,241)"`
 -LinePattern 1 -Text "Scripting Client" -VerticalAlign '0'`
 -CharSize "14 pt"
Draw-VisioLine -BeginX 0.4297 -BeginY 5.1979 -EndX 3.0834 -EndY 5.1979 -LineWeight "0.5 pt" -LineColor "RGB(0,0,0)"

# Step 16.
# Draw Powershell Icon
# Set Position, Size
# Set Text
Draw-VisioIcon -IconPath "c:\!\powershell.png" -Width 0.9843 -Height 0.9843 -PinX 1.7631 -PinY 4.6015 `
 -Text "Windows Powershell" -CharSize "10 pt"

# Step 17.
# Draw Line communication from Scripting Client to WCF
# Set Arrow
Draw-VisioLine -BeginX 3.158 -BeginY 4.5729 -EndX 3.5191 -EndY 4.5729 -LineColor "RGB(255,255,255)" -BeginArrow 4 -EndArrow 4

# Step 18.
# Draw Microsoft System Center
# Virtual Machine Manager Server 2007 Rectangle
# Set Size, Set Colour
# Set Text, Align
Draw-VisioItem -Master "Rectangle" -X 6.3281 -Y 8.2812 -Width 1.5 -Height 2.8125 -FillForegnd "RGB(255,192,0)"`
 -LinePattern 1 -Text "Microsoft System Center Virtual Machine Manager Server 2007" -CharSize "14 pt"

# Step 19.
# Draw Microsoft SQL Server 2005 Rectangle
# Set Size, Set Colour
# Set Text, Align
Draw-VisioItem -Master "Rectangle" -X 6.3281 -Y 4.9219 -Width 1.5 -Height 2.6563 -FillForegnd "RGB(255,192,0)"`
 -LinePattern 1 -Text "Microsoft SQL Server 2005" -CharSize "14 pt"

# Step 20.
# Add Server Items Visio Stensils
# Set Masters item Management Server and Database Server
Add-VisioStensil -Name "Server" -File "SERVER_M.vss"
Set-VisioStensilMasterItem -Stensil "Server" -Item "Management server"
Set-VisioStensilMasterItem -Stensil "Server" -Item "Database server"

# Step 21.
# Draw item Management Server
Draw-VisioItem -Master "Management server" -X 5.6043 -Y 9.7421

# Step 22.
# Draw item Management Server
Draw-VisioItem -Master "Database server" -X 5.5832 -Y 6.3046

# Step 23.
# Draw Line communication from WCF to Microsoft System Center
# Virtual Machine Manager Server 2007
# Set Arrow
Draw-VisioLine -BeginX 5.0052 -BeginY 8.2604 -EndX 5.6024 -EndY 8.2604 -LineColor "RGB(255,255,255)" -BeginArrow 4 -EndArrow 4

# Step 24.
# Draw Line communication from Microsoft System Center
# Virtual Machine Manager Server 2007 to Microsoft SQL Server 2005
# Set Arrow
Draw-VisioLine -BeginX 6.3272 -BeginY 6.2344 -EndX 6.3272 -EndY 6.8802 -LineColor "RGB(255,255,255)" -BeginArrow 4 -EndArrow 0

# Step 25.
# Draw Win-RM Rectangle, Set Size, Set Colour
# Set Text, Align
# Draw Line
Draw-VisioItem -Master "Rectangle" -X 8.4375 -Y 6.9219 -Width 1.5 -Height 6.6563 -FillForegnd "RGB(255,255,255)"`
 -LinePattern 1 -Text "Windows Remote Managemet (Win-RM)" -VerticalAlign '0'`
 -CharSize "14 pt"
Draw-VisioLine -BeginX 7.75 -BeginY 9.1875 -EndX 9.1328 -EndY 9.1875 -LineWeight "0.5 pt" -LineColor "RGB(0,0,0)"

# Step 26.
# Draw Win-RM Icon
# Set Position, Size
Draw-VisioIcon -IconPath "c:\!\Win-RM.png" -Width 1.1563 -Height 1.1563 -PinX 8.4293 -PinY 7

# Step 27.
# Draw Line communication from Win-RM to Microsoft System Center
# Virtual Machine Manager Server 2007
# Set Arrow
Draw-VisioLine -BeginX 7.0781 -BeginY 8.2812 -EndX 7.6753 -EndY 8.2812 -LineColor "RGB(255,255,255)" -BeginArrow 4 -EndArrow 4

# Step 28.
# Draw P2V Source Rectangle, Set Size, Set Colour
# Set Text, Align
# Draw Line
Draw-VisioItem -Master "Rectangle" -X 10.9844 -Y 9.5 -Width 2.7813 -Height 1.5 -FillForegnd "RGB(209,235,241)"`
 -LinePattern 1 -Text "P2V Source" -VerticalAlign '0'`
 -CharSize "14 pt"
Draw-VisioLine -BeginX 9.6485 -BeginY 9.9739 -EndX 12.3021 -EndY 9.9739 -LineWeight "0.5 pt" -LineColor "RGB(0,0,0)"

# Step 29.
# Draw VMM Agent Icon
# Set Position, Size
# Set Text
Draw-VisioIcon -IconPath "c:\!\VMMAgent.png" -Width 0.8438 -Height 0.8438 -PinX 10.2969 -PinY 9.5 `
 -Text "VMM Agent" -CharSize "10 pt"

# Step 30.
# Draw Powershell Icon
# Set Position, Size
# Set Text
Draw-VisioIcon -IconPath "c:\!\powershell.png" -Width 0.7968 -Height 0.7968 -PinX 11.6016 -PinY 9.6016 `
 -Text "Windows Powershell" -CharSize "10 pt"

# Step 31.
# Draw Line communication from P2V Source to Win-RM
# Set Arrow
Draw-VisioLine -BeginX 9.1875 -BeginY 9.487 -EndX 9.599 -EndY 9.487 -LineColor "RGB(255,255,255)" -BeginArrow 4 -EndArrow 4

# Step 32.
# Draw Host Rectangle, Set Size, Set Colour
# Set Text, Align
# Draw Line
Draw-VisioItem -Master "Rectangle" -X 10.9792 -Y 6.9427 -Width 2.7813 -Height 1.5 -FillForegnd "RGB(209,235,241)"`
 -LinePattern 1 -Text "Host" -VerticalAlign '0'`
 -CharSize "14 pt"
Draw-VisioLine -BeginX 9.6472 -BeginY 7.4219 -EndX 12.3008 -EndY 7.4219 -LineWeight "0.5 pt" -LineColor "RGB(0,0,0)"

# Step 33.
# Draw VMM Agent Icon
# Set Position, Size
# Set Text
Draw-VisioIcon -IconPath "c:\!\VMMAgent.png" -Width 0.8438 -Height 0.8438 -PinX 10.2917 -PinY 6.9427 `
 -Text "VMM Agent" -CharSize "10 pt"

# Step 34.
# Draw Microsoft Virtual Server 2005 R2 Icon
# Set Position, Size
# Set Text
Draw-VisioIcon -IconPath "c:\!\WS.jpg" -Width 0.8125 -Height 0.7404 -PinX 11.5938 -PinY 6.9423 `
 -Text "Microsoft Virtual Server 2005 R2" -CharSize "7 pt"

# Step 35.
# Draw Line communication from Host to Win-RM
# Set Arrow
Draw-VisioLine -BeginX 9.1849 -BeginY 6.941 -EndX 9.5964 -EndY 6.941 -LineColor "RGB(255,255,255)" -BeginArrow 4 -EndArrow 4

# Step 36.
# Draw Library Rectangle, Set Size, Set Colour
# Set Text, Align
# Draw Line
Draw-VisioItem -Master "Rectangle" -X 10.9792 -Y 4.3542 -Width 2.7813 -Height 1.5 -FillForegnd "RGB(209,235,241)"`
 -LinePattern 1 -Text "Library" -VerticalAlign '0'`
 -CharSize "14 pt"
Draw-VisioLine -BeginX 9.6419 -BeginY 4.8073 -EndX 12.2955 -EndY 4.8073 -LineWeight "0.5 pt" -LineColor "RGB(0,0,0)"

# Step 37.
# Draw VMM Agent Icon
# Set Position, Size
# Set Text
Draw-VisioIcon -IconPath "c:\!\VMMAgent.png" -Width 0.8438 -Height 0.8438 -PinX 10.2917 -PinY 4.3542 `
 -Text "VMM Agent" -CharSize "10 pt"

# Step 38.
# Draw Windows Server 2003 R2 Icon
# Set Position, Size
# Set Text
Draw-VisioIcon -IconPath "c:\!\WS.jpg" -Width 0.8125 -Height 0.7404 -PinX 11.5625 -PinY 4.3702 `
 -Text "Windows Server 2003 R2" -CharSize "7 pt"

# Step 39.
# Draw Line communication from Library to Win-RM
# Set Arrow
Draw-VisioLine -BeginX 9.1901 -BeginY 4.3611 -EndX 9.6016 -EndY 4.3611 -LineColor "RGB(255,255,255)" -BeginArrow 4 -EndArrow 4

# Step 40.
# Draw BITS Rectangle, Set Size, Set Colour
# Set Text, Align
# Draw Line
Draw-VisioItem -Master "Rectangle" -X 10.9844 -Y 8.2292 -Width 2.75 -Height 0.5625 -FillForegnd "RGB(255,255,0)"`
 -LinePattern 1 -Text "BITS" -ParaHorzAlign '0'`
 -CharSize "14 pt"

# Step 41.
# Draw BITS Icon
# Set Position, Size
# Set Text
Draw-VisioIcon -IconPath "c:\!\BITS.jpg" -Width 0.5417 -Height 0.5417 -PinX 10.974 -PinY 8.2344

# Step 42.
# Draw Line communication from BITS to P2V Source
# Set Arrow
Draw-VisioLine -BeginX 10.9844 -BeginY 8.5104 -EndX 10.9844 -EndY 8.75 -LineColor "RGB(255,255,255)" -BeginArrow 4 -EndArrow 4

# Step 43.
# Draw Line communication from BITS to Host
# Set Arrow
Draw-VisioLine -BeginX 10.9844 -BeginY 7.6849 -EndX 10.9844 -EndY 7.9219 -LineColor "RGB(255,255,255)" -BeginArrow 4 -EndArrow 4

# Step 44.
# Draw BITS Rectangle, Set Size, Set Colour
# Set Text, Align
# Draw Line
Draw-VisioItem -Master "Rectangle" -X 10.9844 -Y 5.6555 -Width 2.75 -Height 0.5625 -FillForegnd "RGB(255,255,0)"`
 -LinePattern 1 -Text "BITS" -ParaHorzAlign '0'`
 -CharSize "14 pt"

# Step 45.
# Draw BITS Icon
# Set Position, Size
# Set Text
Draw-VisioIcon -IconPath "c:\!\BITS.jpg" -Width 0.5417 -Height 0.5417 -PinX 10.974 -PinY 5.6607

# Step 46.
# Draw Line communication from BITS to Host 
# Set Arrow
Draw-VisioLine -BeginX 10.9844 -BeginY 5.9245 -EndX 10.9844 -EndY 6.1901 -LineColor "RGB(255,255,255)" -BeginArrow 4 -EndArrow 4

# Step 47.
# Draw Line communication from BITS to Library
# Set Arrow
Draw-VisioLine -BeginX 10.9792 -BeginY 5.1042 -EndX 10.9792 -EndY 5.375 -LineColor "RGB(255,255,255)" -BeginArrow 4 -EndArrow 4

# Step 48.
# Resise Page To Fit Contents
Resize-VisioPageToFitContents

# Step 49.
# Save Document
# And Quit Application
Save-VisioDocument -File 'C:\!\MsSCVMM2007Arch.vsd'
Close-VisioApplication

Поточна версія вищезазначеного коду знаходиться в репозиторії Git за цим посиланням: MsSCVMM2k7ArchDiagramV1.ps1.

Короткий Підсумок.


Отже фінальний результат повністю аналогічний описаному в попередніх публікаціях, проте оптимізація за допомогою функцій дозволила скоротити об’єм коду з 516 рядків до 326.  Код став більш оптимальним і читабельним. Позитивним фактором також являється стратегія повторного використання коду.  

Проте залишаються ще задачі до реалізації: функції мають мати код перевірки вхідних параметрів на коректність, і додати і розширити алгоритми роботи із більш складними фігурами. 

Але про це вже в наступних публікаціях. 

До зустрічі. 

З повагою, AIRRA! 

Опубліковано в категорії: Microsoft, Архітектура, Дизайн, Код, Програмування | Позначки: , , , , , , , , , , , , , , , , | Залишити коментар

Microsoft System Center Virtual Machine Manager 2007 – Фундамент віртуалізованого центру обробки даних. Частина 1. Перший погляд. Загальні характеристики. Інтеграція. Короткий Підсумок.

Перший погляд


Пройшло три роки з часу придбання Microsoft компанії Connectix. І ось, нарешті Microsoft випускає інструмент управління корпоративного сегменту для Virtual Server: Virtual Machine Manager 2007, що входить до сімейства продуктів System Center.

Microsoft System Center Virtual Machine Manager 2007, це комплексне рішення для управління віртуалізованим центром обробки даних, що дозволяє збільшити фізичну утилізацію серверів та забезпечити централізоване управління інфраструктурою віртуальних машин.

Загальні характеристики


Перше видання System Center Virtual Machine Manager містить наступні функції управління віртуальною інфраструктурою:

  • Підтримка життевого циклу експлуатації віртуальних машин;
  • Централізована бібліотека еталонних образів віртуальних машин, скриптів та образів ISO;
  • Швидке та надійне перетворення фізичного сервера у віртуальну машину (P2V міграція);
  • Швидке та надійне перетворення віртуальної машини у віртуальну машину (V2V міграція);
  • Надання функціоналу самообслуговування через веб-портал;
  • Розширені можливості сценаріїв автоматизації завдяки інтеграції з PowerShell;
  • Інтеграція з System Center Operation Manager 2007 для моніторингу віртуального центру обробки даних та планування потужностей;
  • Інтеграція з System Center Configuration Manager 2007 для оновлення віртуальних машин в режимі офлайн;
  • Інтеграція з System Center Manager Data Protection Manager 2007 для резервного копіювання працюючих віртуальних машин.
Малюнок 1: Консоль Адміністратора Virtual Machine Manager.

Інтеграція


Консоль адміністратора Virtual Machine Manager створена на звичному користувальницькому інтерфейсі Operations Manager 2007, завдяки чому адміністратори швидко та легко зможуть управляти своїми віртуальними машинами. Комплексний моніторинг стану здоров’я хостів, віртуальних машин, серверів бібліотек та компонентів Virtual Machine Manager надається через Virtualization Management Pack в Operations Manager 2007.

System Center Virtual Machine Manager також інтегрований із знайомими інструментами та технологіями. Наприклад, Virtual Machine Manager використовує базу даних SQL Server для зберігання даних про продуктивність та конфігурацію, а можливості звітності в Virtual Machine Manager використовують знайомі технології SQL Reporting Services, котрі, щоправда надаються через System Center Operations Manager.

Короткий Підсумок


Отже, перший випуск Microsoft System Center Virtual Machine Manager 2007 показав себе як повноцінне рішення для управління віртуалізованим середовищем. Інтеграція з іншими продуктами System Center та підтримка PowerShell відкривають широкі можливості для адміністраторів.

Проте основна увага у наступних публікаціях буде приділена саме архітектурі SCVMM — від принципів побудови до оптимальних моделей розгортання в корпоративній інфраструктурі.

Детальніше про це — у наступних матеріалах.

До зустрічі, за кілька днів.
З повагою, AIRRA!

Опубліковано в категорії: Microsoft, Віртуалізація, Ретроспектива, Технології | Позначки: , , , , , , , , , , , | Залишити коментар

Архітектура і Дизайн. Код і Програмування. Частина 2. Вступ. Microsoft Visio і Powershell. Перші кроки. Короткий Підсумок і Наступні кроки.

 

Вступ


Привіт усім читачам блогу про ІТ Архітектуру і Навчання

Продовжуємо публікацію статей під концептуальною назвою “Архітектура і Дизайн. Впровадження і Експлуатація. Код і Програмування”

У минулому матеріалі мова йшла про цю концепцію загалом і про створення середовища і налаштування інструментів для розробки коду.

Сьогодні ми почнемо написання коду для відображення схеми архітектури системи Microsoft System Center Virtual Machine Manager 2007 у форматі Visio для відповідної серії статей. 

Microsoft Visio і Powershel. Перші кроки


Отже почнемо із простих кроків.

Створимо обєкт застосунку Visio і новий документ на основі пустого шаблону. Встановимо активну сторінку, на котрій в подальшому будемо програмно малювати нашу архітектурну схему.

# Step 1.
# Create Visio Object
# Create Document from Blank Template
# Set Active Page
$Application = New-Object -ComObject Visio.Application
$Application.Visible = $True
$Documents = $Application.Documents
$Document=$Application.Documents.Add('')
$Page=$Application.ActivePage
$Application.ActivePage.PageSheet

Додаємо трафарети базових фігур (BASIC_M.vss). Спершу нам буде потрібен шаблон прямокутника.

# Step 2.
# Add Basic Visio Stensils
# Set Masters Item Rectangle
$Stensil1 = $Application.Documents.Add("BASIC_M.vss")
$Rectangle = $Stensil1.Masters.Item("Rectangle")

Малюємо прямокутник із забарвленням, і надписом “Microsoft Virtual Machine Manager Architecture”. Текст вирівнюємо по верхньому краю прямокутника і зліва. Ця фігура буде основою нашої схеми. Для естетичного підкреслення надпису намалюємо під ним лінію відповідного кольору.

# Step 3.
# Draw Main Rectangle, Set Size, Set Colour
# Set Text, Size, Color, Align
# Draw Line, Set Weight, Color
$Shape1 = $Page.Drop($Rectangle, 6.375, 7.125)
$Shape1.Cells('Width').Formula = '12.2501'
$Shape1.Cells('Height').Formula = '7.25'
$Shape1.Cells('FillForegnd').Formula = '=RGB(0,153,204)'
$Shape1.Cells('LinePattern').Formula = 0
$Shape1.Text = "Microsoft Virtual Machine Manager Architecture"
$Shape1.Cells('VerticalAlign') = 0
$Shape1.Cells('Para.HorzAlign') = 0
$Shape1.Cells('Char.Size').Formula = '20 pt'
$Shape1.Cells('Char.Color').Formula = '=RGB(255,255,255)'
$Line1 = $Page.DrawLine(0.3125, 10.3438, 12.4948, 10.3438)
$Line1.Cells('LineWeight').Formula = '1 pt'
$Line1.Cells('LineColor').Formula = '=RGB(255,255,255)'

Проміжний результат виконання попередніх кроків виглядає так:

Малюнок 1. Результат виконання перших трьох фрагментів Powershell Коду.

Аналогічно, малюємо прямокутник, що буде відображати клієнтську систему.

# Step 4.
# Draw Client Rectangle, Set Size, Set Colour
# Set Text, Align
# Draw Line
$Shape2 = $Page.Drop($Rectangle, 1.7656, 9.2344)
$Shape2.Cells('Width').Formula = '2.7813'
$Shape2.Cells('Height').Formula = '1.9688'
$Shape2.Cells('FillForegnd').Formula = '=RGB(209,235,241)'
$Shape2.Cells('LinePattern').Formula = 1
$Shape2.Text = "Client"
$Shape2.Cells('VerticalAlign') = 0
$Shape2.Cells('Char.Size').Formula = '14 pt'
$Line2 = $Page.DrawLine(0.4297, 9.9427, 3.0833, 9.9427)
$Line2.Cells('LineWeight').Formula = '0.5 pt'
$Line2.Cells('LineColor').Formula = '=RGB(0,0,0)'

В межах цього прямокутника буде кілька обєктів. Додаємо трафарети фігур компьютерної тематики (COMPS_M.vss), і будемо працювати із шаблоном піктограми Персонального компьютера “PC”.

# Step 5.
# Add Computer Items Visio Stensils
# Set Masters item PC
$Stensil2 = $Application.Documents.Add("COMPS_M.vss")
$PC1 = $Stensil2.Masters.Item("PC")

Додаємо зображення Персонального Компьютера із Підписом “Administrator Console”.

# Step 6.
# Draw item PC
# Set Text, Size
$Shape3 = $Page.Drop($PC1, 1.1173, 9.1693)
$Shape3.Text = "Administrator Console"
$Shape3.Cells('Char.Size').Formula = '10 pt'

Додаємо піктограмму PowerShell. В цьому випадку будемо використовувати підготовлений зазделегідь малюнок у форматі PNG (PowerShell.png).

# Step 7.
# Draw Powershell Icon
# Set Position, Size
# Set Text
$Picture1 = $Page.Import("c:\!\powershell.png")
$Picture1.Cells('Width').Formula = '0.9843'
$Picture1.Cells('Height').Formula = '0.9843'
$Picture1.Cells('PinX').Formula = '2.5547'
$Picture1.Cells('PinY').Formula = '9.2682'
$Picture1.Text = "Windows Powershell"
$Picture1.Cells('Char.Size').Formula = '10 pt'

Малюємо прямокутник, котрий буде відображати програмний інтерфейс комунікації клієнтських систем із серверними – Windows Communication Foundation.

# Step 8.
# Draw WCF Rectangle, Set Size, Set Colour
# Set Text, Align
# Draw Line
$Shape4 = $Page.Drop($Rectangle, 4.2682, 6.9063)
$Shape4.Cells('Width').Formula = '1.5'
$Shape4.Cells('Height').Formula = '6.625'
$Shape4.Cells('FillForegnd').Formula = '=RGB(255,255,255)'
$Shape4.Cells('LinePattern').Formula = 1
$Shape4.Text = "Windows Communication Foundation"
$Shape4.Cells('VerticalAlign') = 0
$Shape4.Cells('Char.Size').Formula = '14 pt'
$Line3 = $Page.DrawLine(3.5664, 9.4063, 4.9492, 9.4063)
$Line3.Cells('LineWeight').Formula = '0.5 pt'
$Line3.Cells('LineColor').Formula = '=RGB(0,0,0)'

Додаємо пікторамму WCF.

# Step 9.
# Draw WCF Icon
# Set Position, Size
$Picture2 = $Page.Import("c:\!\WCF.png")
$Picture2.Cells('Width').Formula = '1.412'
$Picture2.Cells('Height').Formula = '1.0443'
$Picture2.Cells('PinX').Formula = '4.2708'
$Picture2.Cells('PinY').Formula = '6.9779'

З’єднуємо два об’єкти лінією – Клієнтську Систему із програмним інтерфейсом Windows Communication Foundation. Це буде відображати двосторонню комунікацію.

# Step 10.
# Draw Line communication from Client to WCF
# Set Arrow
$Line4 = $Page.DrawLine(3.1563, 9.2396, 3.5174, 9.2396)
$Line4.Cells('LineColor').Formula = '=RGB(255,255,255)'
$Line4.Cells('BeginArrow').Formula=4
$Line4.Cells('EndArrow').Formula=4

Додаємо прямокутник, що буде відображати веб клієнта. 

# Step 11.
# Draw Web Client Rectangle, Set Size, Set Colour
# Set Text, Align
# Draw Line
$Shape5 = $Page.Drop($Rectangle, 1.7656, 6.8776)
$Shape5.Cells('Width').Formula = '2.7813'
$Shape5.Cells('Height').Formula = '2.1094'
$Shape5.Cells('FillForegnd').Formula = '=RGB(209,235,241)'
$Shape5.Cells('LinePattern').Formula = 1
$Shape5.Text = "Web Client"
$Shape5.Cells('VerticalAlign') = 0
$Shape5.Cells('Char.Size').Formula = '14 pt'
$Line5 = $Page.DrawLine(0.4297, 7.6562, 3.0833, 7.6562)
$Line5.Cells('LineWeight').Formula = '0.5 pt'
$Line5.Cells('LineColor').Formula = '=RGB(0,0,0)'

Аналогічно попереднім крокам додаємо піктограмму Веб порталу Самообслуговування (SelfServicePortal.png) і ще одну піктограмму PowerShell.

# Step 12.
# Draw Self Service Portal Icon
# Set Position, Size
# Set Text
$Picture3 = $Page.Import("c:\!\SelfServicePortal.png")
$Picture3.Cells('Width').Formula = '0.8438'
$Picture3.Cells('Height').Formula = '0.8438'
$Picture3.Cells('PinX').Formula = '1.1094'
$Picture3.Cells('PinY').Formula = '6.9271'
$Picture3.Text = "Self Service Portal"
$Picture3.Cells('Char.Size').Formula = '10 pt'
# Step 13.
# Draw Powershell Icon
# Set Position, Size
# Set Text
$Picture4 = $Page.Import("c:\!\powershell.png")
$Picture4.Cells('Width').Formula = '0.9843'
$Picture4.Cells('Height').Formula = '0.9843'
$Picture4.Cells('PinX').Formula = '2.4922'
$Picture4.Cells('PinY').Formula = '6.9192'
$Picture4.Text = "Windows Powershell"
$Picture4.Cells('Char.Size').Formula = '10 pt'

Аналогічно знову з’єднуємо два обєкти лінією – Веб Клієнта із програмним інтерфейсом Windows Communication Foundation. Це також буде відображати двосторонню комунікацію.

# Step 14.
# Draw Line communication from Web Client to WCF
# Set Arrow
$Line6 = $Page.DrawLine(3.158, 6.8802, 3.5191, 6.8802)
$Line6.Cells('LineColor').Formula = '=RGB(255,255,255)'
$Line6.Cells('BeginArrow').Formula=4
$Line6.Cells('EndArrow').Formula=4

І завершує клієнтську картину прямокутник, що відображає Scripting Client із ще одною піктограмою PowerShell. І звичайно ж, зєднуємо цей об’єкт із програмним інтерфейсом Windows Communication Foundation двосторонньою комунікацією.

# Step 15.
# Draw Scripting Client Rectangle, Set Size, Set Colour
# Set Text, Align
# Draw Line
$Shape6 = $Page.Drop($Rectangle, 1.7657, 4.5469)
$Shape6.Cells('Width').Formula = '2.7813'
$Shape6.Cells('Height').Formula = '1.9062'
$Shape6.Cells('FillForegnd').Formula = '=RGB(209,235,241)'
$Shape6.Cells('LinePattern').Formula = 1
$Shape6.Text = "Scripting Client"
$Shape6.Cells('VerticalAlign') = 0
$Shape6.Cells('Char.Size').Formula = '14 pt'
$Line7 = $Page.DrawLine(0.4297, 5.1979, 3.0834, 5.1979)
$Line7.Cells('LineWeight').Formula = '0.5 pt'
$Line7.Cells('LineColor').Formula = '=RGB(0,0,0)'
# Step 16.
# Draw Powershell Icon
# Set Position, Size
# Set Text
$Picture5 = $Page.Import("c:\!\powershell.png")
$Picture5.Cells('Width').Formula = '0.9843'
$Picture5.Cells('Height').Formula = '0.9843'
$Picture5.Cells('PinX').Formula = '1.7631'
$Picture5.Cells('PinY').Formula = '4.6015'
$Picture5.Text = "Windows Powershell"
$Picture5.Cells('Char.Size').Formula = '10 pt'
# Step 17.
# Draw Line communication from Scripting Client to WCF
# Set Arrow
$Line8 = $Page.DrawLine(3.158, 4.5729, 3.5191, 4.5729)
$Line8.Cells('LineColor').Formula = '=RGB(255,255,255)'
$Line8.Cells('BeginArrow').Formula=4
$Line8.Cells('EndArrow').Formula=4

Результат виконання попередніх кроків виглядає так:

Малюнок 2. Проміжний результат виконання попередніх фрагментів Powershell Коду.

Тепер перейдемо до основних сервісів. Для візуалізації роботи серверної частини використаємо трафарети фігур відповідної тематики (SERVER_M.vss), і будемо працювати із шаблонами піктограм Сервера управління “Management server” і Сервера бази даних “Database server”. Спершу малюємо прямокутник для візуалізації Microsoft System Center Virtual Machine Manager Server 2007 і відповідно інший для Microsoft SQL Server 2005. Відповідні Піктограми серверів розташовуємо поверх прямокутників зліва вверху. І звичайно ж з’єднуємо обєкт “Microsoft System Center Virtual Machine Manager Server 2007” із програмним інтерфейсом Windows Communication Foundation двосторонньою комунікацією, а із Microsoft SQL Server 2005 односторонньою.

# Step 18.
# Draw Microsoft System Center
# Virtual Machine Manager Server 2007 Rectangle
# Set Size, Set Colour
# Set Text, Align
$Shape7 = $Page.Drop($Rectangle, 6.3281, 8.2812)
$Shape7.Cells('Width').Formula = '1.5'
$Shape7.Cells('Height').Formula = '2.8125'
$Shape7.Cells('FillForegnd').Formula = '=RGB(255,192,0)'
$Shape7.Cells('LinePattern').Formula = 1
$Shape7.Text = "Microsoft System Center Virtual Machine Manager Server 2007"
$Shape7.Cells('Char.Size').Formula = '14 pt'
# Step 19.
# Draw Microsoft SQL Server 2005 Rectangle
# Set Size, Set Colour
# Set Text, Align
$Shape8 = $Page.Drop($Rectangle, 6.3281, 4.9219)
$Shape8.Cells('Width').Formula = '1.5'
$Shape8.Cells('Height').Formula = '2.6563'
$Shape8.Cells('FillForegnd').Formula = '=RGB(255,192,0)'
$Shape8.Cells('LinePattern').Formula = 1
$Shape8.Text = "Microsoft SQL Server 2005"
$Shape8.Cells('Char.Size').Formula = '14 pt'
# Step 20.
# Add Server Items Visio Stensils
# Set Masters item Management Server and Database Server
$Stensil3 = $Application.Documents.Add("SERVER_M.vss")
$MS1 = $Stensil3.Masters.Item("Management server")
$DBS1 = $Stensil3.Masters.Item("Database server")
# Step 21.
# Draw item Management Server
$Shape9 = $Page.Drop($MS1, 5.6043, 9.7421)
# Step 22.
# Draw item Management Server
$Shape10 = $Page.Drop($DBS1, 5.5832, 6.3046)
# Step 23.
# Draw Line communication from WCF to Microsoft System Center
# Virtual Machine Manager Server 2007
# Set Arrow
$Line9 = $Page.DrawLine(5.0052, 8.2604, 5.6024, 8.2604)
$Line9.Cells('LineColor').Formula = '=RGB(255,255,255)'
$Line9.Cells('BeginArrow').Formula=4
$Line9.Cells('EndArrow').Formula=4
# Step 24.
# Draw Line communication from Microsoft System Center
# Virtual Machine Manager Server 2007 to Microsoft SQL Server 2005
# Set Arrow
$Line10 = $Page.DrawLine(6.3272, 6.2344, 6.3272, 6.8802)
$Line10.Cells('LineColor').Formula = '=RGB(255,255,255)'
$Line10.Cells('BeginArrow').Formula=4
$Line10.Cells('EndArrow').Formula=0

Результат виконання попередніх кроків виглядає так:

Малюнок 3. Проміжний результат виконання попередніх фрагментів Powershell Коду.

Взаємодію Microsoft System Center Virtual Machine Manager Server 2007 із агентськими системами забезпечує технологія Windows Remote Management (Win-RM). Отож намалюємо цей компонент архітектури аналогічно тому, як малювали відображення програмного інтерфейсу Windows Communication Foundation. І з’єднаємо цей компонент із об’єктом Microsoft System Center Virtual Machine Manager Server 2007 двосторонньою комунікацією.

# Step 25.
# Draw Win-RM Rectangle, Set Size, Set Colour
# Set Text, Align
# Draw Line
$Shape11 = $Page.Drop($Rectangle, 8.4375, 6.9219)
$Shape11.Cells('Width').Formula = '1.5'
$Shape11.Cells('Height').Formula = '6.6563'
$Shape11.Cells('FillForegnd').Formula = '=RGB(255,255,255)'
$Shape11.Cells('LinePattern').Formula = 1
$Shape11.Text = "Windows Remote Managemet (Win-RM)"
$Shape11.Cells('VerticalAlign') = 0
$Shape11.Cells('Char.Size').Formula = '14 pt'
$Line11 = $Page.DrawLine(7.75, 9.1875, 9.1328, 9.1875)
$Line11.Cells('LineWeight').Formula = '0.5 pt'
$Line11.Cells('LineColor').Formula = '=RGB(0,0,0)'
# Step 26.
# Draw Win-RM Icon
# Set Position, Size
$Picture6 = $Page.Import("c:\!\Win-RM.png")
$Picture6.Cells('Width').Formula = '1.1563'
$Picture6.Cells('Height').Formula = '1.1563'
$Picture6.Cells('PinX').Formula = '8.4293'
$Picture6.Cells('PinY').Formula = '7'
# Step 27.
# Draw Line communication from Win-RM to Microsoft System Center
# Virtual Machine Manager Server 2007
# Set Arrow
$Line12 = $Page.DrawLine(7.0781, 8.2812, 7.6753, 8.2812)
$Line12.Cells('LineColor').Formula = '=RGB(255,255,255)'
$Line12.Cells('BeginArrow').Formula=4
$Line12.Cells('EndArrow').Formula=4

Взаємодія із хостами віртуалізації, Бібліотекою, тощо базуються на основі VMM Агента. Почнемо відображати ці компоненти архітектури з візуалізації взаємодії процесів міграції сервісів з фізичного середовища у віртуальне: P2V Source. Нам буде потрібен прямокутник, лінія, піктограми VMM Агента і Powershell. І звичайно ж відображенння двосторонньої комунікації із технологією Windows Remote Managemet (Win-RM).

# Step 28.
# Draw P2V Source Rectangle, Set Size, Set Colour
# Set Text, Align
# Draw Line
$Shape12 = $Page.Drop($Rectangle, 10.9844, 9.5)
$Shape12.Cells('Width').Formula = '2.7813'
$Shape12.Cells('Height').Formula = '1.5'
$Shape12.Cells('FillForegnd').Formula = '=RGB(209,235,241)'
$Shape12.Cells('LinePattern').Formula = 1
$Shape12.Text = "P2V Source"
$Shape12.Cells('VerticalAlign') = 0
$Shape12.Cells('Char.Size').Formula = '14 pt'
$Line13 = $Page.DrawLine(9.6485, 9.9739, 12.3021, 9.9739)
$Line13.Cells('LineWeight').Formula = '0.5 pt'
$Line13.Cells('LineColor').Formula = '=RGB(0,0,0)'
# Step 29.
# Draw VMM Agent Icon
# Set Position, Size
# Set Text
$Picture7 = $Page.Import("c:\!\VMMAgent.png")
$Picture7.Cells('Width').Formula = '0.8438'
$Picture7.Cells('Height').Formula = '0.8438'
$Picture7.Cells('PinX').Formula = '10.2969'
$Picture7.Cells('PinY').Formula = '9.5'
$Picture7.Text = "VMM Agent"
$Picture7.Cells('Char.Size').Formula = '10 pt'
# Step 30.
# Draw Powershell Icon
# Set Position, Size
# Set Text
$Picture8 = $Page.Import("c:\!\powershell.png")
$Picture8.Cells('Width').Formula = '0.7968'
$Picture8.Cells('Height').Formula = '0.7968'
$Picture8.Cells('PinX').Formula = '11.6016'
$Picture8.Cells('PinY').Formula = '9.6016'
$Picture8.Text = "Windows Powershell"
$Picture8.Cells('Char.Size').Formula = '10 pt'
# Step 31.
# Draw Line communication from P2V Source to Win-RM
# Set Arrow
$Line14 = $Page.DrawLine(9.1875, 9.487, 9.599, 9.487)
$Line14.Cells('LineColor').Formula = '=RGB(255,255,255)'
$Line14.Cells('BeginArrow').Formula=4
$Line14.Cells('EndArrow').Formula=4

Аналогічно, відображаємо Хости віртуалізації – Microsoft Virtual Server 2005 R2.

# Step 32.
# Draw Host Rectangle, Set Size, Set Colour
# Set Text, Align
# Draw Line
$Shape13 = $Page.Drop($Rectangle, 10.9792, 6.9427)
$Shape13.Cells('Width').Formula = '2.7813'
$Shape13.Cells('Height').Formula = '1.5'
$Shape13.Cells('FillForegnd').Formula = '=RGB(209,235,241)'
$Shape13.Cells('LinePattern').Formula = 1
$Shape13.Text = "Host"
$Shape13.Cells('VerticalAlign') = 0
$Shape13.Cells('Char.Size').Formula = '14 pt'
$Line15 = $Page.DrawLine(9.6472, 7.4219, 12.3008, 7.4219)
$Line15.Cells('LineWeight').Formula = '0.5 pt'
$Line15.Cells('LineColor').Formula = '=RGB(0,0,0)'
# Step 33.
# Draw VMM Agent Icon
# Set Position, Size
# Set Text
$Picture9 = $Page.Import("c:\!\VMMAgent.png")
$Picture9.Cells('Width').Formula = '0.8438'
$Picture9.Cells('Height').Formula = '0.8438'
$Picture9.Cells('PinX').Formula = '10.2917'
$Picture9.Cells('PinY').Formula = '6.9427'
$Picture9.Text = "VMM Agent"
$Picture9.Cells('Char.Size').Formula = '10 pt'
# Step 34.
# Draw Microsoft Virtual Server 2005 R2 Icon
# Set Position, Size
# Set Text
$Picture10 = $Page.Import("c:\!\WS.jpg")
$Picture10.Cells('Width').Formula = '0.8125'
$Picture10.Cells('Height').Formula = '0.7404'
$Picture10.Cells('PinX').Formula = '11.5938'
$Picture10.Cells('PinY').Formula = '6.9423'
$Picture10.Text = "Microsoft Virtual Server 2005 R2"
$Picture10.Cells('Char.Size').Formula = '7 pt'
# Step 35.
# Draw Line communication from Host to Win-RM
# Set Arrow
$Line16 = $Page.DrawLine(9.1849, 6.941, 9.5964, 6.941)
$Line16.Cells('LineColor').Formula = '=RGB(255,255,255)'
$Line16.Cells('BeginArrow').Formula=4
$Line16.Cells('EndArrow').Formula=4

І подібно до попередніх кроків, відображаємо елементи Бібліотеки.

# Step 36.
# Draw Library Rectangle, Set Size, Set Colour
# Set Text, Align
# Draw Line
$Shape14 = $Page.Drop($Rectangle, 10.9792, 4.3542)
$Shape14.Cells('Width').Formula = '2.7813'
$Shape14.Cells('Height').Formula = '1.5'
$Shape14.Cells('FillForegnd').Formula = '=RGB(209,235,241)'
$Shape14.Cells('LinePattern').Formula = 1
$Shape14.Text = "Library"
$Shape14.Cells('VerticalAlign') = 0
$Shape14.Cells('Char.Size').Formula = '14 pt'
$Line17 = $Page.DrawLine(9.6419, 4.8073, 12.2955, 4.8073)
$Line17.Cells('LineWeight').Formula = '0.5 pt'
$Line17.Cells('LineColor').Formula = '=RGB(0,0,0)'
# Step 37.
# Draw VMM Agent Icon
# Set Position, Size
# Set Text
$Picture11 = $Page.Import("c:\!\VMMAgent.png")
$Picture11.Cells('Width').Formula = '0.8438'
$Picture11.Cells('Height').Formula = '0.8438'
$Picture11.Cells('PinX').Formula = '10.2917'
$Picture11.Cells('PinY').Formula = '4.3542'
$Picture11.Text = "VMM Agent"
$Picture11.Cells('Char.Size').Formula = '10 pt'
# Step 38.
# Draw Windows Server 2003 R2 Icon
# Set Position, Size
# Set Text
$Picture12 = $Page.Import("c:\!\WS.jpg")
$Picture12.Cells('Width').Formula = '0.8125'
$Picture12.Cells('Height').Formula = '0.7404'
$Picture12.Cells('PinX').Formula = '11.5625'
$Picture12.Cells('PinY').Formula = '4.3702'
$Picture12.Text = "Windows Server 2003 R2"
$Picture12.Cells('Char.Size').Formula = '7 pt'
# Step 39.
# Draw Line communication from Library to Win-RM
# Set Arrow
$Line18 = $Page.DrawLine(9.1901, 4.3611, 9.6016, 4.3611)
$Line18.Cells('LineColor').Formula = '=RGB(255,255,255)'
$Line18.Cells('BeginArrow').Formula=4
$Line18.Cells('EndArrow').Formula=4

Результат виконання попередніх кроків виглядає так:

Малюнок 4. Проміжний результат виконання попередніх фрагментів Powershell Коду.

Взаємодія між Хостами віртуалізації, Бібліотекою і процесами міграції сервісів з фізичного середовища у віртуальне: P2V Source здійснюється за допомогою технології Background Intelligent Transfer Service (BITS). Відобразимо цю двосторонню взаємодію між кінцевими елементами архітектури.

# Step 40.
# Draw BITS Rectangle, Set Size, Set Colour
# Set Text, Align
# Draw Line
$Shape15 = $Page.Drop($Rectangle, 10.9844, 8.2292)
$Shape15.Cells('Width').Formula = '2.75'
$Shape15.Cells('Height').Formula = '0.5625'
$Shape15.Cells('FillForegnd').Formula = '=RGB(255,255,0)'
$Shape15.Cells('LinePattern').Formula = 1
$Shape15.Text = "BITS"
$Shape15.Cells('Para.HorzAlign') = 0
$Shape15.Cells('Char.Size').Formula = '14 pt'
# Step 41.
# Draw BITS Icon
# Set Position, Size
# Set Text
$Picture13 = $Page.Import("c:\!\BITS.jpg")
$Picture13.Cells('Width').Formula = '0.5417'
$Picture13.Cells('Height').Formula = '0.5417'
$Picture13.Cells('PinX').Formula = '10.974'
$Picture13.Cells('PinY').Formula = '8.2344'
# Step 42.
# Draw Line communication from BITS to P2V Source
# Set Arrow
$Line19 = $Page.DrawLine(10.9844, 8.5104, 10.9844, 8.75)
$Line19.Cells('LineColor').Formula = '=RGB(255,255,255)'
$Line19.Cells('BeginArrow').Formula=4
$Line19.Cells('EndArrow').Formula=4
# Step 43.
# Draw Line communication from BITS to Host
# Set Arrow
$Line20 = $Page.DrawLine(10.9844, 7.6849, 10.9844, 7.9219)
$Line20.Cells('LineColor').Formula = '=RGB(255,255,255)'
$Line20.Cells('BeginArrow').Formula=4
$Line20.Cells('EndArrow').Formula=4
# Step 44.
# Draw BITS Rectangle, Set Size, Set Colour
# Set Text, Align
# Draw Line
$Shape16 = $Page.Drop($Rectangle, 10.9844, 5.6555)
$Shape16.Cells('Width').Formula = '2.75'
$Shape16.Cells('Height').Formula = '0.5625'
$Shape16.Cells('FillForegnd').Formula = '=RGB(255,255,0)'
$Shape16.Cells('LinePattern').Formula = 1
$Shape16.Text = "BITS"
$Shape16.Cells('Para.HorzAlign') = 0
$Shape16.Cells('Char.Size').Formula = '14 pt'
# Step 45.
# Draw BITS Icon
# Set Position, Size
# Set Text
$Picture14 = $Page.Import("c:\!\BITS.jpg")
$Picture14.Cells('Width').Formula = '0.5417'
$Picture14.Cells('Height').Formula = '0.5417'
$Picture14.Cells('PinX').Formula = '10.974'
$Picture14.Cells('PinY').Formula = '5.6607'
# Step 46.
# Draw Line communication from BITS to Host 
# Set Arrow
$Line21 = $Page.DrawLine(10.9844, 5.9245, 10.9844, 6.1901)
$Line21.Cells('LineColor').Formula = '=RGB(255,255,255)'
$Line21.Cells('BeginArrow').Formula=4
$Line21.Cells('EndArrow').Formula=4
# Step 47.
# Draw Line communication from BITS to Library
# Set Arrow
$Line22 = $Page.DrawLine(10.9792, 5.1042, 10.9792, 5.375)
$Line22.Cells('LineColor').Formula = '=RGB(255,255,255)'
$Line22.Cells('BeginArrow').Formula=4
$Line22.Cells('EndArrow').Formula=4

І наостанок виконаємо зміну розміру сторінки згідно розмірів нашої діаграми, збережемо її у вигляді файлу на диску і здійснимо закриття додатку Visio.

# Step 48.
# Resise Page To Fit Contents
$Page.ResizeToFitContents()
# Step 49.
# Save Document
# And Quit Application
$Document.SaveAs(“C:\!\MsSCVMM2007Arch.vsd”)
$Application.Quit()

Кінцевий результат схеми показаний на малюнку.

Малюнок 5. Фінальний результат виконання Powershell Коду.

Поточна версія вищезазначеного коду знаходиться в репозиторії Git за цим посиланням: VisioPowershellv01.ps1.

Короткий Підсумок і Наступні кроки


Отже фінальний результат повністю задовільняє наші очікування. За допомогою Powershell Коду була створена схема архітектури системи Microsoft System Center Virtual Machine Manager 2007.

Проте даний підхід має суттєві недоліки.

Загальний об’єм цього коду нараховує понад 500 рядків. Тому тема наступної публікації це оптимізація цього коду за допомогою функцій Powershell.

Але про це вже в наступній публікації.

До зустрічі, за кілька днів.
З повагою AIRRA!

Опубліковано в категорії: Microsoft, Архітектура, Дизайн, Код, Програмування | Позначки: , , , , , , , , , , , , , , , , , , , , , , , , | Залишити коментар