Architektura i projektowanie. Kod i programowanie. Część 3. Wstęp. Funkcje PowerShell. PSVisio.ps1. MsSCVMM2k7ArchDiagramV1.ps1. Krótkie podsumowanie.

 

Wstęp


Witam wszystkich czytelników bloga poświęconego architekturze IT i szkoleniom.

Kontynuujemy publikację artykułów pod wspólnym tytułem „Architektura i projektowanie. Wdrożenie i eksploatacja. Kod i programowanie”.

W poprzednim materiale omawialiśmy sposób przedstawienia schematu architektury systemu Microsoft System Center Virtual Machine Manager 2007 w formacie Visio w ramach dedykowanego cyklu artykułów. Do realizacji tego zadania wykorzystaliśmy kod PowerShell. Rezultat w pełni spełnił nasze oczekiwania. Jednak istotnym minusem okazała się duża objętość kodu oraz brak strategii jego ponownego użycia. Dzięki funkcjom możemy uporządkować bloki kodu tak, aby móc je wielokrotnie wykorzystywać i jednocześnie zmniejszyć jego ogólną objętość.

Temu właśnie będzie poświęcony ten wpis.

Funkcje PowerShell


Aby korzystać z funkcji PowerShell, konieczne jest umieszczenie kodu w pliku oraz zastosowanie odpowiedniej składni poleceń i inicjalizacji tych elementów. Dlatego utworzymy nowy plik PSVisio.ps1, w którym zgromadzimy wszystkie nasze rozwiązania.

Aby zainicjalizować kod napisanych przez nas funkcji PowerShell, należy wykonać następujące polecenie:

. .\PSVisio.ps1

W przypadku wprowadzenia zmian w kodzie, zmodyfikowaną funkcję należy ponownie załadować poleceniem:

rm Function:\NameOfFunction

A następnie ponownie należy wykonać inicjalizację poleceniem opisanym powyżej.

Na początku tworzenia naszego kodu i uzupełniania go funkcjami plik PSVisio.ps1 będzie zawierał nagłówek w formie komentarzy oraz początkową inicjalizację kilku zmiennych. Zostaną one wykorzystane do tworzenia nazw obiektów poprzez ich kolejne numerowanie:

#######################################################################
#
# 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 

Przypomnijmy sobie początkowy fragment kodu, który opisaliśmy w poprzednim wpisie:

# 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")

Jak widać, zaczyna się on od poleceń tworzących obiekt aplikacji Visio. Uporządkujmy te proste kroki w postaci pierwszej funkcji – 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
}

Funkcja okazała się dość prosta i nie wymaga żadnych parametrów. Nie zapominajmy o dodawaniu komentarzy wyjaśniających nasz kod.

New-VisioDocument

Opiszmy kolejną funkcję służącą do tworzenia nowego dokumentu Visio: New-VisioDocument.

Funkcja utworzy nowy dokument Visio na podstawie pustego szablonu. Funkcja ta również nie posiada żadnych parametrów wejściowych.

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 

Funkcja Set-VisioPage również jest prosta. Jej logika polega na ustawieniu aktywnej strony, która będzie podstawą naszej przyszłej schemy. Funkcja nie posiada parametrów wejściowych.

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

W Visio figury opierają się na szablonach (stencils). Dlatego zadaniem kolejnej funkcji Add-VisioStensil jest dodanie szablonów figur z odpowiedniego pliku .vss. Funkcja przyjmuje dwa parametry wejściowe: Name – nazwa obiektu szablonu, File – nazwa pliku szablonów.

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

Aby pracować z konkretną figurą, należy określić, który element będzie głównym wzorcem figury. Logikę tej operacji zaimplementujemy w postaci funkcji Set-VisioStensilMasterItem. Funkcja posiada dwa parametry wejściowe: Stensil – nazwa obiektu szablonu, Item – nazwa figury.

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

Dotarliśmy wreszcie do funkcji, które będą wykonywać operacje tworzenia i wyświetlania obiektów o określonych właściwościach. Na początek będą to proste figury geometryczne – prostokąt, koło, linia itp.

Ponownie przypomnijmy sobie fragment kodu, który wykonuje te operacje. 

# 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'

Funkcja Draw-VisioItem posiada trzy obowiązkowe parametry: Master – nazwa wzorca figury, współrzędne położenia X i Y. Pozostałe parametry, takie jak: FillForegnd – kolor wypełnienia figury, LinePattern – styl linii obrysu figury, Text – tekst figury, VerticalAlign i ParaHorzAlign – parametry wyrównania tekstu w pionie i poziomie, CharSize i CharColor – rozmiar i kolor znaków tekstu, są opcjonalne.

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

Funkcja Draw-VisioLine została opracowana do rysowania różnych linii. Posiada kilka obowiązkowych parametrów: współrzędne początku BeginX, BeginY oraz końca EndX, EndY. Dodatkowo można określić parametry opcjonalne: LineColor – kolor linii, BeginArrow, EndArrow – styl strzałek na początku i końcu linii.

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

Funkcja Draw-VisioIcon umożliwia dodawanie do schematów wcześniej przygotowanych ikon w formacie .png lub .jpeg. Posiada kilka obowiązkowych parametrów: IconPath – ścieżka i nazwa pliku ikony, wymiary Width, Height, współrzędne PinX, PinY. Parametry opcjonalne to: Text – tekst etykiety, CharSize – rozmiar znaków tekstu.

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

Funkcja Resize-VisioPageToFitContents jest niezwykle prosta – jej zadaniem jest dopasowanie rozmiaru strony do wymiarów rysunku. Funkcja nie posiada parametrów wejściowych.

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

Pozostały drobne, końcowe kroki. Logika funkcji Save-VisioDocument polega na zapisaniu utworzonej diagramu w postaci pliku Visio .vsd. Funkcja posiada obowiązkowy parametr File – nazwa pliku 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 

Kończy tę linię narracyjną funkcja Close-VisioApplication. Nie posiada parametrów, a jej logika polega wyłącznie na zamknięciu aplikacji 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


Ostateczny rezultat kodu funkcji w pliku PSVisio.ps1 wygląda następująco:  

#######################################################################
#
# 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
	}
}

Aktualna wersja powyższego kodu znajduje się w repozytorium Git pod tym linkiem: PSVisio.ps1.

MsSCVMM2k7ArchDiagramV1.ps1


Odpowiednio, kod tworzenia diagramu architektury systemu Microsoft System Center Virtual Machine Manager 2007 w formacie 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

Aktualna wersja powyższego kodu znajduje się w repozytorium Git pod tym linkiem: MsSCVMM2k7ArchDiagramV1.ps1.

Krótkie podsumowanie


Ostateczny rezultat jest w pełni zgodny z opisanym w poprzednich publikacjach, jednak optymalizacja przy użyciu funkcji pozwoliła zmniejszyć objętość kodu z 516 wierszy do 326. Kod stał się bardziej optymalny i czytelny. Dodatkowym atutem jest strategia ponownego użycia kodu.

Pozostają jednak jeszcze zadania do zrealizowania: funkcje powinny zawierać kod sprawdzający poprawność parametrów wejściowych oraz rozbudować algorytmy obsługi bardziej złożonych figur.

O tym jednak opowiemy w kolejnych publikacjach.

Do zobaczenia.

Z poważaniem, AIRRA! 

Zaszufladkowano do kategorii Architektura, Kod, Microsoft, Programowanie, Projekt | Otagowano , , , , , , , , , , , , , , , , | Dodaj komentarz

Microsoft System Center Virtual Machine Manager 2007 – Podstawa zwirtualizowanego centrum danych. Część 1. Pierwsze spojrzenie. Funkcje ogólne. Integracja. Krótkie Podsumowanie.

Pierwsze spojrzenie


Minęły trzy lata, odkąd Microsoft przejął Connectix. Wreszcie, firma Microsoft udostępnia narzędzie do zarządzania segmentem przedsiębiorstwa dla serwera wirtualnego: Virtual Machine Manager 2007, część rodziny produktów System Center.

Microsoft System Center Virtual Machine Manager 2007 to kompleksowe rozwiązanie do zarządzania zwirtualizowanym centrum danych, które umożliwia zwiększone wykorzystanie fizycznego serwera i scentralizowane zarządzanie infrastrukturą maszyn wirtualnych.

Funkcje ogólne


Pierwsza edycja programu System Center Virtual Machine Manager zawiera następujące funkcje zarządzania infrastrukturą wirtualną:

  • Wsparcie dla cyklu życia działania maszyn wirtualnych;
  • Scentralizowana biblioteka obrazów referencyjnych maszyn wirtualnych, skryptów i obrazów ISO;
  • Szybka i niezawodna konwersja serwera fizycznego na maszynę wirtualną (migracja P2V);
  • Szybka i niezawodna konwersja maszyny wirtualnej na maszynę wirtualną (migracja V2V);
  • Udostępnianie funkcji samoobsługi za pośrednictwem portalu internetowego;
  • Dodatkowe skrypty automatyzacji dzięki integracji z PowerShell;
  • Integracja z System Center Operation Manager 2007 do monitorowania wirtualnego centrum danych i planowania wydajności;
  • Integracja z programem System Center Configuration Manager 2007 w celu aktualizacji maszyn wirtualnych w trybie offline;
  • Integracja z programem System Center Manager Data Protection Manager 2007 w celu tworzenia kopii zapasowych działających maszyn wirtualnych.
Rysunek 1: Konsola administratora programu Virtual Machine Manager.

Integracja


Konsola administratora programu Virtual Machine Manager jest oparta na znanym interfejsie użytkownika programu Operations Manager 2007, dzięki czemu administratorzy mogą szybko i łatwo zarządzać swoimi maszynami wirtualnymi. Kompleksowe monitorowanie stanu hostów, maszyn wirtualnych, serwerów bibliotek i składników programu Virtual Machine Manager jest dostępne w pakiecie Virtualization Management Pack w programie Operations Manager 2007.

Program System Center Virtual Machine Manager jest również zintegrowany ze znanymi narzędziami i technologiami. Na przykład Virtual Machine Manager używa bazy danych SQL Server do przechowywania danych dotyczących wydajności i konfiguracji, podczas gdy funkcje raportowania w programie Virtual Machine Manager korzystają ze znanych technologii usług SQL Reporting Services, ale są udostępniane za pośrednictwem programu System Center Operations Manager.

Krótkie Podsumowanie


Pierwsza wersja Microsoft System Center Virtual Machine Manager 2007 okazała się kompleksowym rozwiązaniem do zarządzania środowiskami wirtualnymi. Integracja z innymi produktami System Center oraz wsparcie PowerShell otwierają szerokie możliwości dla administratorów.

Jednak w nadchodzących publikacjach główny nacisk będzie położony na architekturę SCVMM — od zasad projektowania po optymalne modele wdrażania w infrastrukturach korporacyjnych.

Więcej szczegółów zostanie przedstawionych w kolejnych materiałach.

Do zobaczenia za kilka dni.
Z poważaniem, AIRRA!

 

Zaszufladkowano do kategorii Microsoft, Retrospektywa, Technologia, Wirtualizacja | Otagowano , , , , , , , , , , , | Dodaj komentarz

Architektura i design. Kod i programowanie. Część 2. Wstęp. Microsoft Visio i Powershell. Pierwsze kroki. Krótkie podsumowanie i kolejne kroki.

 

Wstęp


Witam wszystkich czytelników bloga o Architekturze IT i Edukacji.

Kontynuujemy publikację artykułów pod konceptualnym tytułem „Architektura i Design. Wdrażanie i eksploatacja. Kod i programowanie”

W poprzednim artykule mówiliśmy ogólnie o tej koncepcji oraz o tworzeniu środowiska i konfigurowaniu narzędzi do tworzenia kodu.

Dzisiaj zaczniemy pisać kod wyświetlający diagram architektury systemu Microsoft System Center Virtual Machine Manager 2007 w formacie Visio dla powiązanej serii artykułów.

Microsoft Visio i PowerShell. Pierwsze kroki


Zacznijmy więc od prostych kroków.

Utwórzmy obiekt aplikacji Visio i nowy dokument na podstawie pustego szablonu. Ustawmy aktywną stronę, na której później programowo narysujemy nasz schemat architektoniczny.

# 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

Dodajemy szablony podstawowych kształtów (BASIC_M.vss). Najpierw potrzebujemy szablonu prostokąta.

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

Rysujemy prostokąt z kolorem i napisem „Microsoft Virtual Machine Manager Architecture”. Tekst wyrównujemy wzdłuż górnej krawędzi prostokąta i do lewej. Ta liczba będzie podstawą naszego schematu. Aby estetycznie podkreślić napis, narysuj pod nim linię w odpowiednim kolorze.

# 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)'

Pośredni wynik poprzednich kroków wygląda tak:

Rysunek 1. Wynik pierwszych trzech fragmentów kodu Powershell.

Podobnie narysuj prostokąt, który będzie wyświetlał system klienta.

# 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)'

W tym prostokącie będzie kilka obiektów. Dodamy szablony figur o tematyce komputerowej (COMPS_M.vss) i będziemy pracować z szablonem ikony komputera osobistego „PC”.

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

Załączamy obraz Komputera Osobistego z podpisem „Konsola administratora”.

# 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'

Dodaj ikonę PowerShell. W takim przypadku wykorzystamy zdjęcie przygotowane wcześniej w formacie 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'

Rysujemy prostokąt, który wyświetli programowy interfejs komunikacji między systemami klienckimi a systemami serwerowymi – 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)'

Dodaj ikonę 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'

Łączymy linią dwa obiekty – System Klienta z interfejsem programowym Windows Communication Foundation. Będzie to odzwierciedlać komunikację dwukierunkową.

# 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

Dodaj prostokąt, który wyświetli klienta WWW.

# 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)'

Podobnie jak w poprzednich krokach, dodajemy ikonę samoobsługowego portalu internetowego (SelfServicePortal.png) i kolejną ikonę 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'

Podobnie łączymy te dwa obiekty ponownie linią – Web Client z interfejsem oprogramowania Windows Communication Foundation. Odzwierciedla to również komunikację dwukierunkową.

# 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

A uzupełnienie obrazu klienta to prostokąt przedstawiający klienta skryptów z inną ikoną PowerShell. I oczywiście łączymy ten obiekt z interfejsem oprogramowania Windows Communication Foundation za pomocą komunikacji dwukierunkowej.

# 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

Wynik poprzednich kroków wygląda tak:

Rysunek 2. Pośredni wynik wykonania poprzednich fragmentów kodu Powershell.

Przejdźmy teraz do głównych usług. Do wizualizacji pracy części serwerowej użyjemy szablonów rycin o odpowiednim temacie (SERVER_M.vss) oraz będziemy pracować z szablonami ikon Management Server „Management server” oraz Database Server „Database server” . Najpierw rysujemy prostokąt do wizualizacji Microsoft System Center Virtual Machine Manager Server 2007 i odpowiednio inny dla Microsoft SQL Server 2005. Umieszczamy odpowiednie ikony serwerów na górze prostokątów w lewym górnym rogu. I oczywiście łączymy obiekt „Microsoft System Center Virtual Machine Manager Server 2007” z interfejsem oprogramowania Windows Communication Foundation za pomocą komunikacji dwukierunkowej, a z Microsoft SQL Server 2005 za pomocą komunikacji jednokierunkowej.

# 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

Wynik poprzednich kroków wygląda tak:

Rysunek 3. Pośredni wynik wykonania poprzednich fragmentów kodu Powershell.

Microsoft System Center Virtual Machine Manager Server 2007 współdziała z systemami agentów przy użyciu technologii Windows Remote Management (Win-RM). Narysujmy więc ten składnik architektury w taki sam sposób, w jaki narysowaliśmy wyświetlanie interfejsu oprogramowania Windows Communication Foundation. I połączmy ten komponent z obiektem Microsoft System Center Virtual Machine Manager Server 2007 za pomocą komunikacji dwukierunkowej.

# 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

Interakcja z hostami wirtualizacji, biblioteką itp. oparta jest na VMM Agent. Zacznijmy wyświetlać te komponenty architektury od wizualizacji interakcji procesów migracji usług ze środowiska fizycznego do wirtualnego: Źródło P2V. Będziemy potrzebować prostokąta, linii, ikon VMM Agent i Powershell. I oczywiście wyświetlaj dwukierunkową komunikację dzięki technologii 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

Podobnie wyświetlamy Hosty wirtualizacji – 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

I podobnie jak w poprzednich krokach wyświetlamy elementy Biblioteki.

# 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

Wynik poprzednich kroków wygląda tak:

Rysunek 4. Pośredni wynik wykonania poprzednich fragmentów kodu Powershell.

Interakcja pomiędzy Hostami Wirtualizacji, Biblioteką i procesami migracji usług ze środowiska fizycznego do wirtualnego: Źródło P2V odbywa się z wykorzystaniem technologii Inteligentnego Transferu w Tle (BITS). Pokażemy tę dwukierunkową interakcję pomiędzy końcowymi elementami architektury.

# 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

Na koniec zmienimy rozmiar strony zgodnie z wymiarami naszego diagramu, zapiszemy jako plik na dysku i zamkniemy aplikację Visio.

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

Ostateczny wynik schematu pokazano na rysunku.

Rysunek 5. Ostateczny wynik wykonania kodu Powershell.

Aktualna wersja powyższego kodu znajduje się w repozytorium Git pod tym linkiem: VisioPowershellv01.ps1.

Krótkie podsumowanie i Kolejne kroki


Dlatego efekt końcowy w pełni spełnia nasze oczekiwania. Przy pomocy kodu Powershell powstał schemat architektury systemu Microsoft System Center Virtual Machine Manager 2007.

Podejście to ma jednak istotne wady.

Całkowita objętość tego kodu to ponad 500 wierszy. Dlatego tematem kolejnego wpisu jest optymalizacja tego kodu za pomocą funkcji Powershell.

Ale to zostanie omówione w następnej publikacji.

Do zobaczenia za kilka dni.
Z poważaniem, AIRRA!

Zaszufladkowano do kategorii Architektura, Kod, Microsoft, Programowanie, Projekt | Otagowano , , , , , , , , , , , , , , , , , , , , , , , | Dodaj komentarz

Architektura i design. Kod i programowanie. Część 1. Wstęp. Cykl życia rozwiązania informatycznego. Architektura i design. Kod i programowanie. Microsoft Visio i PowerShell. Środowisko i narzędzia do tworzenia kodu. Krótkie podsumowanie.

 

Wstęp


Witam wszystkich czytelników bloga IT Architektura i Edukacja.

Temat dzisiejszej publikacji będzie dość nietypowy. Będzie on dotyczył „Architektury i Projektowania. Wdrażania i Eksploatacji. Kodowania i Programowania”. Zauważyłaś dziwną kombinację. Ale nie wyciągaj pochopnych wniosków, usiądź wygodnie, bo będzie tu o czym rozmawiać! Czeka nas dość pokaźna ilość materiału.

A zaczniemy od zrozumienia cyklu życia każdego rozwiązania IT.

Cykl życia rozwiązania IT


Każde rozwiązanie informatyczne zwykle przechodzi przez kilka etapów w czasie swojego istnienia: Projekt – Architektura i Design; Wdrożenie – Wdrożenie komponentów, Ustawienia początkowe, Integracja z systemami firm trzecich; i eksploatacji – Regulamin monitorowania, tworzenia kopii zapasowych itp.

Na każdym z etapów wyspecjalizowani specjaliści operują różnymi danymi wejściowymi, dokumentami, schematami. Do standaryzacji tego procesu często wykorzystywane są różne szablony dokumentów od dostawcy, ale każdy z nich ma swój własny styl i podejście w tej kwestii. A rozwiązanie informatyczne całkowicie od jednego dostawcy to bardzo rzadki przypadek.

Dlatego bardzo chciałbym ujednolicić etapy cyklu życia rozwiązania informatycznego za pomocą Kodu. Na podstawie Kodu uformuj niezbędne elementy architektury i schematu projektowego. Następnie na podstawie Kodu i parametrów uzyskanych na poprzednim etapie wykonaj wstępne wdrożenie systemu, zastosuj ustawienia początkowe, dokonaj integracji z systemami firm trzecich. A w ostatecznej wersji podaj przykłady Kodu dla typowych zadań operacyjnych.

Cóż, tę trudną pracę trzeba zacząć od etapu architektury i projektowania.

Architektura i design. Kod i programowanie


Niedawno opublikowałem początek serii artykułów dotyczących technologii Microsoft System Center Virtual Machine Manager 2007. Kolejnym tematem publikacji było omówienie architektury tego produktu. I tutaj warto zrobić sobie krótką przerwę w tym cyklu artykułów, aby zastosować nasze nowe podejście koncepcyjne.

Do wizualizacji architektonicznej zasady działania systemu stosuje się zwykle różne schematy. W tym kontekście szeroko stosowany jest zestaw narzędzi w postaci Microsoft Office Visio. Microsoft Windows Powershell zyskuje popularność w zadaniach automatyzacji. I tu rodzi się logiczny pomysł, a jeśli połączysz te dwie technologie, używając kodu Powershell, najpierw stwórz schemat architektoniczny rozwiązania IT w formacie Visio. Dlaczego nie. Spróbujmy.

Ostateczna wersja diagramu architektury systemu Microsoft System Center Virtual Machine Manager 2007 wygląda tak:

Rysunek 1. Wynik wizualizacji architektury Microsoft System Center Virtual Machine Manager 2007 z wykorzystaniem kodu Powershell i elementów diagramu Microsoft Visio.

W tej serii artykułów postaramy się wykorzystać kod Powershell do stworzenia schematu jak najbardziej podobnego.

Microsoft Visio i PowerShell. Środowisko i narzędzia do tworzenia kodu


Aby pracować nad skryptami kodu, będziemy potrzebować systemu operacyjnego z zainstalowanym następującym oprogramowaniem: Microsoft Visio, Powershell i dowolnym edytorem kodu.

W moim przypadku użyłem:

  • System operacyjny: Microsoft Windows Vista Business, x64;
  • Program do automatyzacji zadań i zarządzania konfiguracjami dla Windows: Microsoft Windows PowerShell 1.0 x64;
  • Edytor do pisania kodu: Notepad++ 32-bit x86 v.4.2;
  • Edytor wykresów dla Windows: Microsoft Office Visio 2007 Professional x86.

Trzymając się strategii „Anything as Code”, wykorzystałem również technologie automatyzacji i „cichej” instalacji podczas wdrażania środowiska programistycznego i pisania kodu.

System operacyjny

Następujące składniki i technologie zostały użyte do automatycznego wdrożenia systemu operacyjnego Microsoft Windows Vista Business, x64:

  • Plik obrazu: en_windows_vista_x64_dvd_x12-40712.iso, który został nagrany na nośniku DVD;
  • Plik skryptu do automatycznej instalacji i konfiguracji podstawowego obrazu systemu operacyjnego Microsoft Windows Vista Business, x64 – Autounattend.xml, zapisany na wymiennym nośniku USB.

Zawartość pliku skryptu do automatycznej instalacji i konfiguracji podstawowego obrazu systemu operacyjnego Microsoft Windows Vista Business, x64 – Autounattend.xml jest podana poniżej:

<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
	<settings pass="windowsPE">
		<component name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
			<SetupUILanguage>
				<UILanguage>en-US</UILanguage>
			</SetupUILanguage>
			<InputLocale>1033:00000409</InputLocale>
			<SystemLocale>en-US</SystemLocale>
			<UILanguage>en-US</UILanguage>
			<UILanguageFallback>en-US</UILanguageFallback>
			<UserLocale>en-US</UserLocale>
		</component>
		<component name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
			<SetupUILanguage>
				<UILanguage>en-US</UILanguage>
			</SetupUILanguage>
			<InputLocale>1033:00000409</InputLocale>
			<SystemLocale>en-US</SystemLocale>
			<UILanguage>en-US</UILanguage>
			<UILanguageFallback>en-US</UILanguageFallback>
			<UserLocale>en-US</UserLocale>
		</component>
		<component name="Microsoft-Windows-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
			<DiskConfiguration>
				<Disk wcm:action="add">
					<DiskID>0</DiskID>
					<CreatePartitions>
						<CreatePartition wcm:action="add">
							<Order>1</Order>
							<Size>100</Size>
							<Type>Primary</Type>
						</CreatePartition>
						<CreatePartition wcm:action="add">
							<Order>2</Order>
							<Extend>true</Extend>
							<Type>Primary</Type>
						</CreatePartition>
					</CreatePartitions>
					<WillWipeDisk>true</WillWipeDisk>
					<ModifyPartitions>
						<ModifyPartition wcm:action="add">
							<Active>true</Active>
							<Format>NTFS</Format>
							<Order>1</Order>
							<PartitionID>1</PartitionID>
							<Label>System Reserved</Label>
						</ModifyPartition>
						<ModifyPartition wcm:action="add">
							<Active>true</Active>
							<Format>NTFS</Format>
							<Label>OS</Label>
							<Letter>C</Letter>
							<Order>2</Order>
							<PartitionID>2</PartitionID>
						</ModifyPartition>
					</ModifyPartitions>
				</Disk>
				<WillShowUI>OnError</WillShowUI>
			</DiskConfiguration>
			<UserData>
				<AcceptEula>true</AcceptEula>
				<FullName></FullName>
				<Organization></Organization>
				<ProductKey>
					<Key>12345-ABCDE-67890-FGHIJ-KLMNO</Key>
				</ProductKey>
			</UserData>
			<ImageInstall>
				<OSImage>
					<InstallFrom>
						<MetaData wcm:action="add">
							<Key>/IMAGE/NAME</Key>
							<Value>Windows Vista BUSINESS</Value>
						</MetaData>
					</InstallFrom>
					<InstallTo>
						<DiskID>0</DiskID>
						<PartitionID>2</PartitionID>
					</InstallTo>
					<WillShowUI>OnError</WillShowUI>
					<InstallToAvailablePartition>false</InstallToAvailablePartition>
				</OSImage>
			</ImageInstall>
		</component>
		<component name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
			<DiskConfiguration>
				<Disk wcm:action="add">
					<DiskID>0</DiskID>
					<CreatePartitions>
						<CreatePartition wcm:action="add">
							<Order>1</Order>
							<Size>100</Size>
							<Type>Primary</Type>
						</CreatePartition>
						<CreatePartition wcm:action="add">
							<Order>2</Order>
							<Extend>true</Extend>
							<Type>Primary</Type>
						</CreatePartition>
					</CreatePartitions>
					<WillWipeDisk>true</WillWipeDisk>
					<ModifyPartitions>
						<ModifyPartition wcm:action="add">
							<Active>true</Active>
							<Format>NTFS</Format>
							<Order>1</Order>
							<PartitionID>1</PartitionID>
							<Label>System Reserved</Label>
						</ModifyPartition>
						<ModifyPartition wcm:action="add">
							<Active>true</Active>
							<Format>NTFS</Format>
							<Label>OS</Label>
							<Letter>C</Letter>
							<Order>2</Order>
							<PartitionID>2</PartitionID>
						</ModifyPartition>
					</ModifyPartitions>
				</Disk>
				<WillShowUI>OnError</WillShowUI>
			</DiskConfiguration>
			<UserData>
				<AcceptEula>true</AcceptEula>
				<FullName></FullName>
				<Organization></Organization>
				<ProductKey>
					<Key>12345-ABCDE-67890-FGHIJ-KLMNO</Key>
				</ProductKey>
			</UserData>
			<ImageInstall>
				<OSImage>
					<InstallFrom>
						<MetaData wcm:action="add">
							<Key>/IMAGE/NAME</Key>
							<Value>Windows Vista BUSINESS</Value>
						</MetaData>
					</InstallFrom>
					<InstallTo>
						<DiskID>0</DiskID>
						<PartitionID>2</PartitionID>
					</InstallTo>
					<WillShowUI>OnError</WillShowUI>
					<InstallToAvailablePartition>false</InstallToAvailablePartition>
				</OSImage>
			</ImageInstall>
		</component>
	</settings>
	<settings pass="generalize">
		<component name="Microsoft-Windows-Security-Licensing-SLC" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
			<SkipRearm>1</SkipRearm>
		</component>
		<component name="Microsoft-Windows-Security-Licensing-SLC" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
			<SkipRearm>1</SkipRearm>
		</component>
	</settings>
	<settings pass="specialize">
		<component name="Microsoft-Windows-Security-Licensing-SLC-UX" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
			<SkipAutoActivation>true</SkipAutoActivation>
		</component>
		<component name="Microsoft-Windows-Security-Licensing-SLC-UX" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
			<SkipAutoActivation>true</SkipAutoActivation>
		</component>
		<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
			<ComputerName>ArchDev-PC</ComputerName>
			<ProductKey>12345-ABCDE-67890-FGHIJ-KLMNO</ProductKey>
			<TimeZone>FLE Standard Time</TimeZone>
		</component>
		<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
			<ComputerName>ArchDev-PC</ComputerName>
			<ProductKey>12345-ABCDE-67890-FGHIJ-KLMNO</ProductKey>
			<TimeZone>FLE Standard Time</TimeZone>
		</component>
	</settings>
	<settings pass="oobeSystem">
		<component name="Microsoft-Windows-International-Core" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
			<InputLocale>1033:00000409</InputLocale>
			<UILanguage>en-US</UILanguage>
			<UserLocale>en-US</UserLocale>
		</component>
		<component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
			<InputLocale>1033:00000409</InputLocale>
			<UILanguage>en-US</UILanguage>
			<UserLocale>en-US</UserLocale>
		</component>
		<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
			<RegisteredOwner></RegisteredOwner>
			<OOBE>
				<HideEULAPage>true</HideEULAPage>
				<NetworkLocation>Other</NetworkLocation>
				<ProtectYourPC>1</ProtectYourPC>
				<SkipMachineOOBE>false</SkipMachineOOBE>
				<SkipUserOOBE>false</SkipUserOOBE>
			</OOBE>
			<UserAccounts>
				<LocalAccounts>
					<LocalAccount wcm:action="add">
						<Password>
							<Value>Pa$$w0rd</Value>
							<PlainText>true</PlainText>
						</Password>
						<Description>ArchDev</Description>
						<DisplayName>ArchDev</DisplayName>
						<Group>Administrators</Group>
						<Name>ArchDev</Name>
					</LocalAccount>
				</LocalAccounts>
			</UserAccounts>
			<AutoLogon>
				<Password>
					<Value>Pa$$w0rd</Value>
					<PlainText>true</PlainText>
				</Password>
				<Enabled>true</Enabled>
				<Username>ArchDev</Username>
			</AutoLogon>
			<DisableAutoDaylightTimeSet>false</DisableAutoDaylightTimeSet>
			<FirstLogonCommands>
				<SynchronousCommand wcm:action="add">
					<Order>1</Order>
					<Description>Disable Auto Updates</Description>
					<CommandLine>reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" /v AUOptions /t REG_DWORD /d 1 /f</CommandLine>
				</SynchronousCommand>
				<SynchronousCommand wcm:action="add">
					<Order>2</Order>
					<Description>Hide Set Network Location</Description>
					<CommandLine>reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\NewNetworks" /v NetworkList /t REG_MULTI_SZ /d "" /f</CommandLine>
				</SynchronousCommand>
				<SynchronousCommand wcm:action="add">
					<Order>3</Order>
					<Description>Hide Set Welcome Center Window</Description>
					<CommandLine>reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v WindowsWelcomeCenter /f</CommandLine>
				</SynchronousCommand>
			</FirstLogonCommands>
		</component>
		<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
			<RegisteredOwner></RegisteredOwner>
			<OOBE>
				<HideEULAPage>true</HideEULAPage>
				<NetworkLocation>Other</NetworkLocation>
				<ProtectYourPC>1</ProtectYourPC>
				<SkipMachineOOBE>false</SkipMachineOOBE>
				<SkipUserOOBE>false</SkipUserOOBE>
			</OOBE>
			<UserAccounts>
				<LocalAccounts>
					<LocalAccount wcm:action="add">
						<Password>
							<Value>Pa$$w0rd</Value>
							<PlainText>true</PlainText>
						</Password>
						<Description>ArchDev</Description>
						<DisplayName>ArchDev</DisplayName>
						<Group>Administrators</Group>
						<Name>ArchDev</Name>
					</LocalAccount>
				</LocalAccounts>
			</UserAccounts>
			<AutoLogon>
				<Password>
					<Value>Pa$$w0rd</Value>
					<PlainText>true</PlainText>
				</Password>
				<Enabled>true</Enabled>
				<Username>ArchDev</Username>
			</AutoLogon>
			<DisableAutoDaylightTimeSet>false</DisableAutoDaylightTimeSet>
			<FirstLogonCommands>
				<SynchronousCommand wcm:action="add">
					<Order>1</Order>
					<Description>Disable Auto Updates</Description>
					<CommandLine>reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" /v AUOptions /t REG_DWORD /d 1 /f</CommandLine>
				</SynchronousCommand>
				<SynchronousCommand wcm:action="add">
					<Order>2</Order>
					<Description>Hide Set Network Location Window</Description>
					<CommandLine>reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\NewNetworks" /v NetworkList /t REG_MULTI_SZ /d "" /f</CommandLine>
				</SynchronousCommand>
				<SynchronousCommand wcm:action="add">
					<Order>3</Order>
					<Description>Hide Set Welcome Center Window</Description>
					<CommandLine>reg delete "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v WindowsWelcomeCenter /f</CommandLine>
				</SynchronousCommand>
			</FirstLogonCommands>
		</component>
	</settings>
</unattend>

Aktualna wersja powyższego kodu znajduje się w repozytorium Git pod tym linkiem: Autounattend.xml.

Microsoft Windows PowerShell

Ciche wdrożenie Automatyzacji zadań i Menedżera konfiguracji dla systemu Windows: Microsoft Windows PowerShell 1.0 x64 (Windows6.0-KB928439-x64.msu) odbywa się za pomocą następującego polecenia konsoli wiersza polecenia:

wusa.exe Windows6.0-KB928439-x64.msu /quiet

Uwaga: Podany kod należy uruchomić z uprawnieniami administratora!

Ponieważ Microsoft Windows PowerShell 1.0 jest już dostępny w naszym środowisku programowania kodu, użyjemy tej technologii we wszystkich dalszych krokach.

Notepad++ 

Automatyczne „ciche” wdrożenie edytora do pisania kodu Notepad++ 32-bit x86 v.4.2 zostanie przeprowadzone za pomocą następującego prostego kodu PowerShell:

# Silent Install Notepad++ 4.2 
$Command = ".\4.2_npp.4.2.Installer.exe" 
$Parms = "/S" 
& $Command $Parms 

Uwaga: Podany kod należy uruchomić z uprawnieniami administratora!

W przyszłości będziemy pracować z dużą ilością kodu PowerShell w postaci plików skryptów .ps1 przez cały czas. Domyślnie program PowerShell uniemożliwia uruchamianie takich artefaktów. Dlatego, aby pomyślnie wykonać taki kod PowerShell, należy wykonać następujące polecenie:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted 

Notepad ++ to świetne narzędzie do pisania i edycji kodu PowerShell, ale podstawowa instalacja nie obsługuje składni struktur poleceń PowerShell: podświetlanie, formatowanie itp.

Aby wyeliminować ten problem należy skorzystać z możliwości tworzenia i konfigurowania reguł językowych opisanych przez użytkownika (User Defined Languages). Aby to zrobić, utwórz plik o nazwie userDefineLang.xml w katalogu „%APPDATA%\Notepad++\” z wymaganą zawartością.

<?xml version="1.0"?>
<NotepadPlus>
  <UserLang name="PowerShell" ext="ps1">
    <Settings>
      <Global caseIgnored="yes" />
      <TreatAsSymbol comment="no" commentLine="yes" />
      <PrefixNode words1="yes" words2="no" words3="no" words4="no" />
    </Settings>
    <KeywordLists>
      <Keywords name="Delimiters">"00"00</Keywords>
      <Keywords name="Folder+">{</Keywords>
      <Keywords name="Folder-">}</Keywords>
      <Keywords name="Operators">! " % & ( ) * , / : ; ? @ [ \ ] ^ ` | ~ + < = ></Keywords>
      <Keywords name="Comment">1 2 0#</Keywords>
      <Keywords name="Words1">Add-Content Add-History Add-Member Add-PSSnapin Clear-Content Clear-Item Clear-ItemProperty Clear-Variable Compare-Object ConvertFrom-SecureString Convert-Path ConvertTo-Html ConvertTo-SecureString Copy-Item Copy-ItemProperty Export-Alias Export-Clixml Export-Console Export-Csv ForEach-Object Format-Custom Format-List Format-Table Format-Wide Get-Acl Get-Alias Get-AuthenticodeSignature Get-ChildItem Get-Command Get-Content Get-Credential Get-Culture Get-Date Get-EventLog Get-ExecutionPolicy Get-Help Get-History Get-Host Get-Item Get-ItemProperty Get-Location Get-Member Get-PfxCertificate Get-Process Get-PSDrive Get-PSProvider Get-PSSnapin Get-Service Get-TraceSource Get-UICulture Get-Unique Get-Variable Get-WmiObject Group-Object Import-Alias Import-Clixml Import-Csv Invoke-Expression Invoke-History Invoke-Item Join-Path Measure-Command Measure-Object Move-Item Move-ItemProperty New-Alias New-Item New-ItemProperty New-Object New-PSDrive New-Service New-TimeSpan New-Variable Out-Default Out-File Out-Host Out-Null Out-Printer Out-String Pop-Location Push-Location Read-Host Remove-Item Remove-ItemProperty Remove-PSDrive Remove-PSSnapin Remove-Variable Rename-Item Rename-ItemProperty Resolve-Path Restart-Service Resume-Service Select-Object Select-String Set-Acl Set-Alias Set-AuthenticodeSignature Set-Content Set-Date Set-ExecutionPolicy Set-Item Set-ItemProperty Set-Location Set-PSDebug Set-Service Set-TraceSource Set-Variable Sort-Object Split-Path Start-Service Start-Sleep Start-Transcript Stop-Process Stop-Service Stop-Transcript Suspend-Service Tee-Object Test-Path Trace-Command Update-FormatData Update-TypeData Where-Object Write-Debug Write-Error Write-Host Write-Output Write-Progress Write-Verbose Write-Warning switch function if throw else while break - $ System. Management.</Keywords>
      <Keywords name="Words2">ac asnp clc cli clp clv cpi cpp cvpa diff epal epcsv fc fl foreach % ft fw gal gc gci gcm gdr ghy gi gl gm gp gps group gsv gsnp gu gv gwmi iex ihy ii ipal ipcsv mi mp nal ndr ni nv oh rdr ri rni rnp rp rsnp rv rvpa sal sasv sc select si sl sleep sort sp spps spsv sv tee where ? write cat cd clear cp h history kill lp ls mount mv popd ps pushd pwd r rm rmdir echo cls chdir copy del dir erase move rd ren set type</Keywords>
      <Keywords name="Words3">CIM_DataFile CIM_DirectoryContainsFile CIM_ProcessExecutable CIM_VideoControllerResolution Msft_Providers Msft_WmiProvider_Counters NetDiagnostics Win32_1394Controller Win32_1394ControllerDevice Win32_AccountSID Win32_ActionCheck Win32_ActiveRoute Win32_AllocatedResource Win32_ApplicationCommandLine Win32_ApplicationService Win32_AssociatedBattery Win32_AssociatedProcessorMemory Win32_AutochkSetting Win32_BaseBoard Win32_Battery Win32_Binary Win32_BindImageAction Win32_BIOS Win32_BootConfiguration Win32_Bus Win32_CacheMemory Win32_CDROMDrive Win32_CheckCheck Win32_CIMLogicalDeviceCIMDataFile Win32_ClassicCOMApplicationClasses Win32_ClassicCOMClass Win32_ClassicCOMClassSetting Win32_ClassicCOMClassSettings Win32_ClassInfoAction Win32_ClientApplicationSetting Win32_CodecFile Win32_COMApplicationSettings Win32_ComClassAutoEmulator Win32_ComClassEmulator Win32_CommandLineAccess Win32_ComponentCategory Win32_ComputerSystem Win32_ComputerSystemProcessor Win32_ComputerSystemProduct Win32_ComputerSystemWindowsProductActivationSetting Win32_Condition Win32_ConnectionShare Win32_ControllerHasHub Win32_CreateFolderAction Win32_CurrentProbe Win32_DCOMApplication Win32_DCOMApplicationAccessAllowedSetting Win32_DCOMApplicationLaunchAllowedSetting Win32_DCOMApplicationSetting Win32_DependentService Win32_Desktop Win32_DesktopMonitor Win32_DeviceBus Win32_DeviceMemoryAddress Win32_DfsNode Win32_DfsNodeTarget Win32_DfsTarget Win32_Directory Win32_DirectorySpecification Win32_DiskDrive Win32_DiskDrivePhysicalMedia Win32_DiskDriveToDiskPartition Win32_DiskPartition Win32_DiskQuota Win32_DisplayConfiguration Win32_DisplayControllerConfiguration Win32_DMAChannel Win32_DriverForDevice Win32_DriverVXD Win32_DuplicateFileAction Win32_Environment Win32_EnvironmentSpecification Win32_ExtensionInfoAction Win32_Fan Win32_FileSpecification Win32_FloppyController Win32_FloppyDrive Win32_FontInfoAction Win32_Group Win32_GroupInDomain Win32_GroupUser Win32_HeatPipe Win32_IDEController Win32_IDEControllerDevice Win32_ImplementedCategory Win32_InfraredDevice Win32_IniFileSpecification Win32_InstalledSoftwareElement Win32_IP4PersistedRouteTable Win32_IP4RouteTable Win32_IRQResource Win32_Keyboard Win32_LaunchCondition Win32_LoadOrderGroup Win32_LoadOrderGroupServiceDependencies Win32_LoadOrderGroupServiceMembers Win32_LocalTime Win32_LoggedOnUser Win32_LogicalDisk Win32_LogicalDiskRootDirectory Win32_LogicalDiskToPartition Win32_LogicalFileAccess Win32_LogicalFileAuditing Win32_LogicalFileGroup Win32_LogicalFileOwner Win32_LogicalFileSecuritySetting Win32_LogicalMemoryConfiguration Win32_LogicalProgramGroup Win32_LogicalProgramGroupDirectory Win32_LogicalProgramGroupItem Win32_LogicalProgramGroupItemDataFile Win32_LogicalShareAccess Win32_LogicalShareAuditing Win32_LogicalShareSecuritySetting Win32_LogonSession Win32_LogonSessionMappedDisk Win32_MappedLogicalDisk Win32_MemoryArray Win32_MemoryArrayLocation Win32_MemoryDevice Win32_MemoryDeviceArray Win32_MemoryDeviceLocation Win32_MIMEInfoAction Win32_MotherboardDevice Win32_MountPoint Win32_MoveFileAction Win32_NamedJobObject Win32_NamedJobObjectActgInfo Win32_NamedJobObjectLimit Win32_NamedJobObjectLimitSetting Win32_NamedJobObjectProcess Win32_NamedJobObjectSecLimit Win32_NamedJobObjectSecLimitSetting Win32_NamedJobObjectStatistics Win32_NetworkAdapter Win32_NetworkAdapterConfiguration Win32_NetworkAdapterSetting Win32_NetworkClient Win32_NetworkConnection Win32_NetworkLoginProfile Win32_NetworkProtocol Win32_NTDomain Win32_NTEventlogFile Win32_NTLogEvent Win32_NTLogEventComputer Win32_NTLogEventLog Win32_NTLogEventUser Win32_ODBCAttribute Win32_ODBCDataSourceAttribute Win32_ODBCDataSourceSpecification Win32_ODBCDriverAttribute Win32_ODBCDriverSoftwareElement Win32_ODBCDriverSpecification Win32_ODBCSourceAttribute Win32_ODBCTranslatorSpecification Win32_OnBoardDevice Win32_OperatingSystem Win32_OperatingSystemAutochkSetting Win32_OperatingSystemQFE Win32_OSRecoveryConfiguration Win32_PageFile Win32_PageFileElementSetting Win32_PageFileSetting Win32_PageFileUsage Win32_ParallelPort Win32_Patch Win32_PatchFile Win32_PatchPackage Win32_PCMCIAController Win32_PerfFormattedData_ContentFilter_IndexingServiceFilter Win32_PerfFormattedData_ContentIndex_IndexingService Win32_PerfFormattedData_Fax_FaxServices Win32_PerfFormattedData_IPSec_IPSecv4Driver Win32_PerfFormattedData_IPSec_IPSecv4IKE Win32_PerfFormattedData_ISAPISearch_HttpIndexingService Win32_PerfFormattedData_MSDTC_DistributedTransactionCoordinator Win32_PerfFormattedData_NETFramework_NETCLRExceptions Win32_PerfFormattedData_NETFramework_NETCLRInterop Win32_PerfFormattedData_NETFramework_NETCLRJit Win32_PerfFormattedData_NETFramework_NETCLRLoading Win32_PerfFormattedData_NETFramework_NETCLRLocksAndThreads Win32_PerfFormattedData_NETFramework_NETCLRMemory Win32_PerfFormattedData_NETFramework_NETCLRRemoting Win32_PerfFormattedData_NETFramework_NETCLRSecurity Win32_PerfFormattedData_NTDS_NTDS Win32_PerfFormattedData_PerfDisk_LogicalDisk Win32_PerfFormattedData_PerfDisk_PhysicalDisk Win32_PerfFormattedData_PerfNet_Browser Win32_PerfFormattedData_PerfNet_Redirector Win32_PerfFormattedData_PerfNet_Server Win32_PerfFormattedData_PerfNet_ServerWorkQueues Win32_PerfFormattedData_PerfOS_Cache Win32_PerfFormattedData_PerfOS_Memory Win32_PerfFormattedData_PerfOS_Objects Win32_PerfFormattedData_PerfOS_PagingFile Win32_PerfFormattedData_PerfOS_Processor Win32_PerfFormattedData_PerfOS_System Win32_PerfFormattedData_PerfProc_FullImage_Costly Win32_PerfFormattedData_PerfProc_Image_Costly Win32_PerfFormattedData_PerfProc_JobObject Win32_PerfFormattedData_PerfProc_JobObjectDetails Win32_PerfFormattedData_PerfProc_Process Win32_PerfFormattedData_PerfProc_ProcessAddressSpace_Costly Win32_PerfFormattedData_PerfProc_Thread Win32_PerfFormattedData_PerfProc_ThreadDetails_Costly Win32_PerfFormattedData_RemoteAccess_RASPort Win32_PerfFormattedData_RemoteAccess_RASTotal Win32_PerfFormattedData_RSVP_ACSRSVPInterfaces Win32_PerfFormattedData_RSVP_ACSRSVPService Win32_PerfFormattedData_Spooler_PrintQueue Win32_PerfFormattedData_TapiSrv_Telephony Win32_PerfFormattedData_Tcpip_ICMP Win32_PerfFormattedData_Tcpip_ICMPv6 Win32_PerfFormattedData_Tcpip_IP Win32_PerfFormattedData_Tcpip_IPv4 Win32_PerfFormattedData_Tcpip_IPv6 Win32_PerfFormattedData_Tcpip_NBTConnection Win32_PerfFormattedData_Tcpip_NetworkInterface Win32_PerfFormattedData_Tcpip_TCP Win32_PerfFormattedData_Tcpip_TCPv4 Win32_PerfFormattedData_Tcpip_TCPv6 Win32_PerfFormattedData_Tcpip_UDP Win32_PerfFormattedData_Tcpip_UDPv4 Win32_PerfFormattedData_Tcpip_UDPv6 Win32_PerfFormattedData_TermService_TerminalServices Win32_PerfFormattedData_TermService_TerminalServicesSession Win32_PerfRawData_ASP_ActiveServerPages Win32_PerfRawData_ContentFilter_IndexingServiceFilter Win32_PerfRawData_ContentIndex_IndexingService Win32_PerfRawData_Fax_FaxServices Win32_PerfRawData_FileReplicaConn_FileReplicaConn Win32_PerfRawData_FileReplicaSet_FileReplicaSet Win32_PerfRawData_IAS_IASAccountingClients Win32_PerfRawData_IAS_IASAccountingServer Win32_PerfRawData_IAS_IASAuthenticationClients Win32_PerfRawData_IAS_IASAuthenticationServer Win32_PerfRawData_InetInfo_InternetInformationServicesGlobal Win32_PerfRawData_IPSec_IPSecv4Driver Win32_PerfRawData_IPSec_IPSecv4IKE Win32_PerfRawData_ISAPISearch_HttpIndexingService Win32_PerfRawData_MSDTC_DistributedTransactionCoordinator Win32_PerfRawData_NETFramework_NETCLRExceptions Win32_PerfRawData_NETFramework_NETCLRInterop Win32_PerfRawData_NETFramework_NETCLRJit Win32_PerfRawData_NETFramework_NETCLRLoading Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads Win32_PerfRawData_NETFramework_NETCLRMemory Win32_PerfRawData_NETFramework_NETCLRRemoting Win32_PerfRawData_NETFramework_NETCLRSecurity Win32_PerfRawData_NTDS_NTDS Win32_PerfRawData_NTFSDRV_SMTPNTFSStoreDriver Win32_PerfRawData_PerfDisk_LogicalDisk Win32_PerfRawData_PerfDisk_PhysicalDisk Win32_PerfRawData_PerfNet_Browser Win32_PerfRawData_PerfNet_Redirector Win32_PerfRawData_PerfNet_Server Win32_PerfRawData_PerfNet_ServerWorkQueues Win32_PerfRawData_PerfOS_Cache Win32_PerfRawData_PerfOS_Memory Win32_PerfRawData_PerfOS_Objects Win32_PerfRawData_PerfOS_PagingFile Win32_PerfRawData_PerfOS_Processor Win32_PerfRawData_PerfOS_System Win32_PerfRawData_PerfProc_FullImage_Costly Win32_PerfRawData_PerfProc_Image_Costly Win32_PerfRawData_PerfProc_JobObject Win32_PerfRawData_PerfProc_JobObjectDetails Win32_PerfRawData_PerfProc_Process Win32_PerfRawData_PerfProc_ProcessAddressSpace_Costly Win32_PerfRawData_PerfProc_Thread Win32_PerfRawData_PerfProc_ThreadDetails_Costly Win32_PerfRawData_RemoteAccess_RASPort Win32_PerfRawData_RemoteAccess_RASTotal Win32_PerfRawData_RSVP_ACSPerRSVPService Win32_PerfRawData_RSVP_ACSRSVPInterfaces Win32_PerfRawData_RSVP_ACSRSVPService Win32_PerfRawData_SMTPSVC_SMTPServer Win32_PerfRawData_Spooler_PrintQueue Win32_PerfRawData_TapiSrv_Telephony Win32_PerfRawData_Tcpip_ICMP Win32_PerfRawData_Tcpip_ICMPv6 Win32_PerfRawData_Tcpip_IP Win32_PerfRawData_Tcpip_IPv4 Win32_PerfRawData_Tcpip_IPv6 Win32_PerfRawData_Tcpip_NBTConnection Win32_PerfRawData_Tcpip_NetworkInterface Win32_PerfRawData_Tcpip_TCP Win32_PerfRawData_Tcpip_TCPv4 Win32_PerfRawData_Tcpip_TCPv6 Win32_PerfRawData_Tcpip_UDP Win32_PerfRawData_Tcpip_UDPv4 Win32_PerfRawData_Tcpip_UDPv6 Win32_PerfRawData_TermService_TerminalServices Win32_PerfRawData_TermService_TerminalServicesSession Win32_PerfRawData_W3SVC_WebService Win32_PhysicalMedia Win32_PhysicalMemory Win32_PhysicalMemoryArray Win32_PhysicalMemoryLocation Win32_PingStatus Win32_PNPAllocatedResource Win32_PnPDevice Win32_PnPEntity Win32_PnPSignedDriver Win32_PnPSignedDriverCIMDataFile Win32_PointingDevice Win32_PortableBattery Win32_PortConnector Win32_PortResource Win32_POTSModem Win32_POTSModemToSerialPort Win32_Printer Win32_PrinterConfiguration Win32_PrinterController Win32_PrinterDriver Win32_PrinterDriverDll Win32_PrinterSetting Win32_PrinterShare Win32_PrintJob Win32_Process Win32_Processor Win32_ProductOptional Win32_ProductCheck Win32_ProductResource Win32_ProductSoftwareFeatures Win32_ProgIDSpecification Win32_ProgramGroup Win32_ProgramGroupContents Win32_Property Win32_ProtocolBinding Win32_Proxy Win32_PublishComponentAction Win32_QuickFixEngineering Win32_QuotaSetting Win32_Refrigeration Win32_Registry Win32_RegistryAction Win32_RemoveFileAction Win32_RemoveIniAction Win32_ReserveCost Win32_ScheduledJob Win32_SCSIController Win32_SCSIControllerDevice Win32_SecuritySettingOfLogicalFile Win32_SecuritySettingOfLogicalShare Win32_SelfRegModuleAction Win32_SerialPort Win32_SerialPortConfiguration Win32_SerialPortSetting Win32_ServerConnection Win32_ServerSession Win32_Service Win32_ServiceControl Win32_ServiceSpecification Win32_ServiceSpecificationService Win32_SessionConnection Win32_SessionProcess Win32_ShadowBy Win32_ShadowCopy Win32_ShadowDiffVolumeSupport Win32_ShadowFor Win32_ShadowOn Win32_ShadowProvider Win32_ShadowStorage Win32_ShadowVolumeSupport Win32_Share Win32_ShareToDirectory Win32_ShortcutAction Win32_ShortcutFile Win32_ShortcutSAP Win32_SID Win32_SoftwareElement Win32_SoftwareElementAction Win32_SoftwareElementCheck Win32_SoftwareElementCondition Win32_SoftwareElementResource Win32_SoftwareFeature Win32_SoftwareFeatureAction Win32_SoftwareFeatureCheck Win32_SoftwareFeatureParent Win32_SoftwareFeatureSoftwareElements Win32_SoundDevice Win32_StartupCommand Win32_SubDirectory Win32_SystemAccount Win32_SystemBIOS Win32_SystemBootConfiguration Win32_SystemDesktop Win32_SystemDevices Win32_SystemDriver Win32_SystemDriverPNPEntity Win32_SystemEnclosure Win32_SystemLoadOrderGroups Win32_SystemLogicalMemoryConfiguration Win32_SystemNetworkConnections Win32_SystemOperatingSystem Win32_SystemPartitions Win32_SystemProcesses Win32_SystemProgramGroups Win32_SystemResources Win32_SystemServices Win32_SystemSlot Win32_SystemSystemDriver Win32_SystemTimeZone Win32_SystemUsers Win32_TapeDrive Win32_TCPIPPrinterPort Win32_TemperatureProbe Win32_Terminal Win32_TerminalService Win32_TerminalServiceSetting Win32_TerminalServiceToSetting Win32_TerminalTerminalSetting Win32_Thread Win32_TimeZone Win32_TSAccount Win32_TSClientSetting Win32_TSEnvironmentSetting Win32_TSGeneralSetting Win32_TSLogonSetting Win32_TSNetworkAdapterListSetting Win32_TSNetworkAdapterSetting Win32_TSPermissionsSetting Win32_TSRemoteControlSetting  Win32_TSSessionDirectory Win32_TSSessionDirectorySetting Win32_TSSessionSetting Win32_TypeLibraryAction Win32_UninterruptiblePowerSupply Win32_USBController Win32_USBControllerDevice Win32_USBHub Win32_UserAccount Win32_UserDesktop Win32_UserInDomain Win32_UTCTime Win32_VideoConfiguration Win32_VideoController Win32_VideoSettings Win32_VoltageProbe Win32_Volume Win32_VolumeQuota Win32_VolumeQuotaSetting Win32_VolumeUserQuota Win32_WindowsProductActivation Win32_WMIElementSetting Win32_WMISetting</Keywords>
      <Keywords name="Words4">$ $$ $? $^ $Args $DebugPreference $Error $ErrorActionPreference $false $foreach $HistorySize $HOME $Host $Input $LastExitCode $Match $MshHome $MyInvocation $null $OFS $PSCommandPath $ShellID $StackTrace $true $_</Keywords>
    </KeywordLists>
    <Styles>
      <WordsStyle name="DEFAULT" fontStyle="0" fontName="" bgColor="FFFFFF" fgColor="000000" styleID="11" />
      <WordsStyle name="FOLDEROPEN" fontStyle="0" fontName="" bgColor="FFFFFF" fgColor="000000" styleID="12" />
      <WordsStyle name="FOLDERCLOSE" fontStyle="0" fontName="" bgColor="FFFFFF" fgColor="000000" styleID="13" />
      <WordsStyle name="KEYWORD1" fontStyle="0" fontName="" bgColor="FFFFFF" fgColor="0000FF" styleID="5" />
      <WordsStyle name="KEYWORD2" fontStyle="0" fontName="" bgColor="FFFFFF" fgColor="8000FF" styleID="6" />
      <WordsStyle name="KEYWORD3" fontStyle="0" fontName="" bgColor="FFFFFF" fgColor="FF00FF" styleID="7" />
      <WordsStyle name="KEYWORD4" fontStyle="0" fontName="" bgColor="FFFFFF" fgColor="FF4500" styleID="8" />
      <WordsStyle name="COMMENT" fontStyle="0" fontName="" bgColor="FFFFFF" fgColor="006400" styleID="1" />
      <WordsStyle name="COMMENT LINE" fontStyle="0" fontName="" bgColor="FFFFFF" fgColor="006400" styleID="2" />
      <WordsStyle name="NUMBER" fontStyle="0" fontName="" bgColor="FFFFFF" fgColor="800080" styleID="4" />
      <WordsStyle name="OPERATOR" fontStyle="0" fontName="" bgColor="FFFFFF" fgColor="a9a9a9" styleID="10" />
      <WordsStyle name="DELIMINER1" fontStyle="0" fontName="" bgColor="FFFFFF" fgColor="8b0000" styleID="14" />
      <WordsStyle name="DELIMINER2" fontStyle="0" fontName="" bgColor="FFFFFF" fgColor="000000" styleID="15" />
      <WordsStyle name="DELIMINER3" fontStyle="0" fontName="" bgColor="FFFFFF" fgColor="000000" styleID="16" />
    </Styles>
  </UserLang>
</NotepadPlus>

Aktualna wersja powyższego kodu znajduje się w repozytorium Git pod tym linkiem: userDefineLang.xml.

W tym celu wykorzystamy również możliwości języka PowerShell i wygenerujemy zawartość tego pliku za pomocą poniższego kodu:

###################################################################
#
# Powershell script for generate Notepad++ userDefineLang.xml
#
# Script for Notepad++ Powershell User Define Language support.
# Script create xml file User Define Language - userDefineLang.xml 
# in %APPDATA%\Notepad++\ directory.
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  12.09.2007
# Purpose/Change: Initial script development
#
# Run:
#   
# .\NppPowershellLanguageSupport.ps1
#
####################################################################

$ExportFilePath = "$env:APPDATA\Notepad++\userDefineLang.xml"

$XmlDocument = New-Object System.Xml.XmlDocument
$xmlDeclaration = $XmlDocument.CreateXmlDeclaration("1.0",$Null,$Null)
$Null = $XmlDocument.AppendChild($xmlDeclaration)
$RootNode = $XmlDocument.CreateElement("NotepadPlus")


$UserLangNode = $XmlDocument.CreateElement("UserLang")
$UserLangAttribute = $UserLangNode.SetAttribute("name","PowerShell")
$UserLangAttribute = $UserLangNode.SetAttribute("ext","ps1")

$SettingsNode = $XmlDocument.CreateElement("Settings")

$GlobalNode = $XmlDocument.CreateElement("Global")
$GlobalAttribute = $GlobalNode.SetAttribute("caseIgnored","yes")

$TreatAsSymbolNode = $XmlDocument.CreateElement("TreatAsSymbol")
$TreatAsSymbolAttribute = $TreatAsSymbolNode.SetAttribute("comment","no")
$TreatAsSymbolAttribute = $TreatAsSymbolNode.SetAttribute("commentLine","yes")


$PrefixNode = $XmlDocument.CreateElement("PrefixNode")
$PrefixAttribute = $PrefixNode.SetAttribute("words1","yes")
$PrefixAttribute = $PrefixNode.SetAttribute("words2","no")
$PrefixAttribute = $PrefixNode.SetAttribute("words3","no")
$PrefixAttribute = $PrefixNode.SetAttribute("words4","no")


$Null = $SettingsNode.AppendChild($GlobalNode)
$Null = $SettingsNode.AppendChild($TreatAsSymbolNode)
$Null = $SettingsNode.AppendChild($PrefixNode)

$Null = $UserLangNode.AppendChild($SettingsNode)

$KeywordListsNode = $XmlDocument.CreateElement("KeywordLists")

$KeywordsNode1 = $XmlDocument.CreateElement("Keywords")
$KeywordsAttribute = $KeywordsNode1.SetAttribute("name","Delimiters")
$KeywordsTextNode1 = $XmlDocument.CreateTextNode(""00"00")
$Null = $KeywordsNode1.AppendChild($KeywordsTextNode1)

$KeywordsNode2 = $XmlDocument.CreateElement("Keywords")
$KeywordsAttribute = $KeywordsNode2.SetAttribute("name","Folder+")
$KeywordsTextNode2 = $XmlDocument.CreateTextNode("{")
$Null = $KeywordsNode2.AppendChild($KeywordsTextNode2)

$KeywordsNode3 = $XmlDocument.CreateElement("Keywords")
$KeywordsAttribute = $KeywordsNode3.SetAttribute("name","Folder-")
$KeywordsTextNode3 = $XmlDocument.CreateTextNode("}")
$Null = $KeywordsNode3.AppendChild($KeywordsTextNode3)

$KeywordsNode4 = $XmlDocument.CreateElement("Keywords")
$KeywordsAttribute = $KeywordsNode4.SetAttribute("name","Operators")
$OperatorsSymbols = '! " % & ( ) * , / : ; ? @ [ \ ] ^ ` | ~ + < = >'
$KeywordsTextNode4 = $XmlDocument.CreateTextNode($OperatorsSymbols)
$Null = $KeywordsNode4.AppendChild($KeywordsTextNode4)

$KeywordsNode5 = $XmlDocument.CreateElement("Keywords")
$KeywordsAttribute = $KeywordsNode5.SetAttribute("name","Comment")
$KeywordsTextNode5 = $XmlDocument.CreateTextNode("1 2 0#")
$Null = $KeywordsNode5.AppendChild($KeywordsTextNode5)

$KeywordsNode6 = $XmlDocument.CreateElement("Keywords")
$KeywordsAttribute = $KeywordsNode6.SetAttribute("name","Words1")
$KeywordsTextNode6 = $XmlDocument.CreateTextNode("Add-Content Add-History Add-Member Add-PSSnapin Clear-Content Clear-Item Clear-ItemProperty Clear-Variable Compare-Object ConvertFrom-SecureString Convert-Path ConvertTo-Html ConvertTo-SecureString Copy-Item Copy-ItemProperty Export-Alias Export-Clixml Export-Console Export-Csv ForEach-Object Format-Custom Format-List Format-Table Format-Wide Get-Acl Get-Alias Get-AuthenticodeSignature Get-ChildItem Get-Command Get-Content Get-Credential Get-Culture Get-Date Get-EventLog Get-ExecutionPolicy Get-Help Get-History Get-Host Get-Item Get-ItemProperty Get-Location Get-Member Get-PfxCertificate Get-Process Get-PSDrive Get-PSProvider Get-PSSnapin Get-Service Get-TraceSource Get-UICulture Get-Unique Get-Variable Get-WmiObject Group-Object Import-Alias Import-Clixml Import-Csv Invoke-Expression Invoke-History Invoke-Item Join-Path Measure-Command Measure-Object Move-Item Move-ItemProperty New-Alias New-Item New-ItemProperty New-Object New-PSDrive New-Service New-TimeSpan New-Variable Out-Default Out-File Out-Host Out-Null Out-Printer Out-String Pop-Location Push-Location Read-Host Remove-Item Remove-ItemProperty Remove-PSDrive Remove-PSSnapin Remove-Variable Rename-Item Rename-ItemProperty Resolve-Path Restart-Service Resume-Service Select-Object Select-String Set-Acl Set-Alias Set-AuthenticodeSignature Set-Content Set-Date Set-ExecutionPolicy Set-Item Set-ItemProperty Set-Location Set-PSDebug Set-Service Set-TraceSource Set-Variable Sort-Object Split-Path Start-Service Start-Sleep Start-Transcript Stop-Process Stop-Service Stop-Transcript Suspend-Service Tee-Object Test-Path Trace-Command Update-FormatData Update-TypeData Where-Object Write-Debug Write-Error Write-Host Write-Output Write-Progress Write-Verbose Write-Warning switch function if throw else while break - $ System. Management.")
$Null = $KeywordsNode6.AppendChild($KeywordsTextNode6)

$KeywordsNode7 = $XmlDocument.CreateElement("Keywords")
$KeywordsAttribute = $KeywordsNode7.SetAttribute("name","Words2")
$KeywordsTextNode7 = $XmlDocument.CreateTextNode("ac asnp clc cli clp clv cpi cpp cvpa diff epal epcsv fc fl foreach % ft fw gal gc gci gcm gdr ghy gi gl gm gp gps group gsv gsnp gu gv gwmi iex ihy ii ipal ipcsv mi mp nal ndr ni nv oh rdr ri rni rnp rp rsnp rv rvpa sal sasv sc select si sl sleep sort sp spps spsv sv tee where ? write cat cd clear cp h history kill lp ls mount mv popd ps pushd pwd r rm rmdir echo cls chdir copy del dir erase move rd ren set type")
$Null = $KeywordsNode7.AppendChild($KeywordsTextNode7)

$KeywordsNode8 = $XmlDocument.CreateElement("Keywords")
$KeywordsAttribute = $KeywordsNode8.SetAttribute("name","Words3")
$Words3 = "CIM_DataFile CIM_DirectoryContainsFile CIM_ProcessExecutable CIM_VideoControllerResolution Msft_Providers Msft_WmiProvider_Counters NetDiagnostics Win32_1394Controller Win32_1394ControllerDevice Win32_AccountSID Win32_ActionCheck Win32_ActiveRoute Win32_AllocatedResource Win32_ApplicationCommandLine Win32_ApplicationService Win32_AssociatedBattery Win32_AssociatedProcessorMemory Win32_AutochkSetting Win32_BaseBoard Win32_Battery Win32_Binary Win32_BindImageAction Win32_BIOS Win32_BootConfiguration Win32_Bus Win32_CacheMemory Win32_CDROMDrive Win32_CheckCheck Win32_CIMLogicalDeviceCIMDataFile Win32_ClassicCOMApplicationClasses Win32_ClassicCOMClass Win32_ClassicCOMClassSetting Win32_ClassicCOMClassSettings Win32_ClassInfoAction Win32_ClientApplicationSetting Win32_CodecFile Win32_COMApplicationSettings Win32_ComClassAutoEmulator Win32_ComClassEmulator Win32_CommandLineAccess Win32_ComponentCategory Win32_ComputerSystem Win32_ComputerSystemProcessor Win32_ComputerSystemProduct Win32_ComputerSystemWindowsProductActivationSetting Win32_Condition Win32_ConnectionShare Win32_ControllerHasHub Win32_CreateFolderAction Win32_CurrentProbe Win32_DCOMApplication Win32_DCOMApplicationAccessAllowedSetting Win32_DCOMApplicationLaunchAllowedSetting Win32_DCOMApplicationSetting Win32_DependentService Win32_Desktop Win32_DesktopMonitor Win32_DeviceBus Win32_DeviceMemoryAddress Win32_DfsNode Win32_DfsNodeTarget Win32_DfsTarget Win32_Directory Win32_DirectorySpecification Win32_DiskDrive Win32_DiskDrivePhysicalMedia Win32_DiskDriveToDiskPartition Win32_DiskPartition Win32_DiskQuota Win32_DisplayConfiguration Win32_DisplayControllerConfiguration Win32_DMAChannel Win32_DriverForDevice Win32_DriverVXD Win32_DuplicateFileAction Win32_Environment Win32_EnvironmentSpecification Win32_ExtensionInfoAction Win32_Fan Win32_FileSpecification Win32_FloppyController Win32_FloppyDrive Win32_FontInfoAction Win32_Group Win32_GroupInDomain Win32_GroupUser Win32_HeatPipe Win32_IDEController Win32_IDEControllerDevice Win32_ImplementedCategory Win32_InfraredDevice Win32_IniFileSpecification Win32_InstalledSoftwareElement Win32_IP4PersistedRouteTable Win32_IP4RouteTable Win32_IRQResource Win32_Keyboard Win32_LaunchCondition Win32_LoadOrderGroup Win32_LoadOrderGroupServiceDependencies Win32_LoadOrderGroupServiceMembers Win32_LocalTime Win32_LoggedOnUser Win32_LogicalDisk Win32_LogicalDiskRootDirectory Win32_LogicalDiskToPartition Win32_LogicalFileAccess Win32_LogicalFileAuditing Win32_LogicalFileGroup Win32_LogicalFileOwner Win32_LogicalFileSecuritySetting Win32_LogicalMemoryConfiguration Win32_LogicalProgramGroup Win32_LogicalProgramGroupDirectory Win32_LogicalProgramGroupItem Win32_LogicalProgramGroupItemDataFile Win32_LogicalShareAccess Win32_LogicalShareAuditing Win32_LogicalShareSecuritySetting Win32_LogonSession Win32_LogonSessionMappedDisk Win32_MappedLogicalDisk Win32_MemoryArray Win32_MemoryArrayLocation Win32_MemoryDevice Win32_MemoryDeviceArray Win32_MemoryDeviceLocation Win32_MIMEInfoAction Win32_MotherboardDevice Win32_MountPoint Win32_MoveFileAction Win32_NamedJobObject Win32_NamedJobObjectActgInfo Win32_NamedJobObjectLimit Win32_NamedJobObjectLimitSetting Win32_NamedJobObjectProcess Win32_NamedJobObjectSecLimit Win32_NamedJobObjectSecLimitSetting Win32_NamedJobObjectStatistics Win32_NetworkAdapter Win32_NetworkAdapterConfiguration Win32_NetworkAdapterSetting Win32_NetworkClient Win32_NetworkConnection Win32_NetworkLoginProfile Win32_NetworkProtocol Win32_NTDomain Win32_NTEventlogFile Win32_NTLogEvent Win32_NTLogEventComputer Win32_NTLogEventLog Win32_NTLogEventUser Win32_ODBCAttribute Win32_ODBCDataSourceAttribute Win32_ODBCDataSourceSpecification Win32_ODBCDriverAttribute Win32_ODBCDriverSoftwareElement Win32_ODBCDriverSpecification Win32_ODBCSourceAttribute Win32_ODBCTranslatorSpecification Win32_OnBoardDevice Win32_OperatingSystem Win32_OperatingSystemAutochkSetting Win32_OperatingSystemQFE Win32_OSRecoveryConfiguration Win32_PageFile Win32_PageFileElementSetting Win32_PageFileSetting Win32_PageFileUsage Win32_ParallelPort Win32_Patch Win32_PatchFile Win32_PatchPackage Win32_PCMCIAController Win32_PerfFormattedData_ContentFilter_IndexingServiceFilter Win32_PerfFormattedData_ContentIndex_IndexingService Win32_PerfFormattedData_Fax_FaxServices Win32_PerfFormattedData_IPSec_IPSecv4Driver Win32_PerfFormattedData_IPSec_IPSecv4IKE Win32_PerfFormattedData_ISAPISearch_HttpIndexingService Win32_PerfFormattedData_MSDTC_DistributedTransactionCoordinator Win32_PerfFormattedData_NETFramework_NETCLRExceptions Win32_PerfFormattedData_NETFramework_NETCLRInterop Win32_PerfFormattedData_NETFramework_NETCLRJit Win32_PerfFormattedData_NETFramework_NETCLRLoading Win32_PerfFormattedData_NETFramework_NETCLRLocksAndThreads Win32_PerfFormattedData_NETFramework_NETCLRMemory Win32_PerfFormattedData_NETFramework_NETCLRRemoting Win32_PerfFormattedData_NETFramework_NETCLRSecurity Win32_PerfFormattedData_NTDS_NTDS Win32_PerfFormattedData_PerfDisk_LogicalDisk Win32_PerfFormattedData_PerfDisk_PhysicalDisk Win32_PerfFormattedData_PerfNet_Browser Win32_PerfFormattedData_PerfNet_Redirector Win32_PerfFormattedData_PerfNet_Server Win32_PerfFormattedData_PerfNet_ServerWorkQueues Win32_PerfFormattedData_PerfOS_Cache Win32_PerfFormattedData_PerfOS_Memory Win32_PerfFormattedData_PerfOS_Objects Win32_PerfFormattedData_PerfOS_PagingFile Win32_PerfFormattedData_PerfOS_Processor Win32_PerfFormattedData_PerfOS_System Win32_PerfFormattedData_PerfProc_FullImage_Costly Win32_PerfFormattedData_PerfProc_Image_Costly Win32_PerfFormattedData_PerfProc_JobObject Win32_PerfFormattedData_PerfProc_JobObjectDetails Win32_PerfFormattedData_PerfProc_Process Win32_PerfFormattedData_PerfProc_ProcessAddressSpace_Costly Win32_PerfFormattedData_PerfProc_Thread Win32_PerfFormattedData_PerfProc_ThreadDetails_Costly Win32_PerfFormattedData_RemoteAccess_RASPort Win32_PerfFormattedData_RemoteAccess_RASTotal Win32_PerfFormattedData_RSVP_ACSRSVPInterfaces Win32_PerfFormattedData_RSVP_ACSRSVPService Win32_PerfFormattedData_Spooler_PrintQueue Win32_PerfFormattedData_TapiSrv_Telephony Win32_PerfFormattedData_Tcpip_ICMP Win32_PerfFormattedData_Tcpip_ICMPv6 Win32_PerfFormattedData_Tcpip_IP Win32_PerfFormattedData_Tcpip_IPv4 Win32_PerfFormattedData_Tcpip_IPv6 Win32_PerfFormattedData_Tcpip_NBTConnection Win32_PerfFormattedData_Tcpip_NetworkInterface Win32_PerfFormattedData_Tcpip_TCP Win32_PerfFormattedData_Tcpip_TCPv4 Win32_PerfFormattedData_Tcpip_TCPv6 Win32_PerfFormattedData_Tcpip_UDP Win32_PerfFormattedData_Tcpip_UDPv4 Win32_PerfFormattedData_Tcpip_UDPv6 Win32_PerfFormattedData_TermService_TerminalServices Win32_PerfFormattedData_TermService_TerminalServicesSession Win32_PerfRawData_ASP_ActiveServerPages Win32_PerfRawData_ContentFilter_IndexingServiceFilter Win32_PerfRawData_ContentIndex_IndexingService Win32_PerfRawData_Fax_FaxServices Win32_PerfRawData_FileReplicaConn_FileReplicaConn Win32_PerfRawData_FileReplicaSet_FileReplicaSet Win32_PerfRawData_IAS_IASAccountingClients Win32_PerfRawData_IAS_IASAccountingServer Win32_PerfRawData_IAS_IASAuthenticationClients Win32_PerfRawData_IAS_IASAuthenticationServer Win32_PerfRawData_InetInfo_InternetInformationServicesGlobal Win32_PerfRawData_IPSec_IPSecv4Driver Win32_PerfRawData_IPSec_IPSecv4IKE Win32_PerfRawData_ISAPISearch_HttpIndexingService Win32_PerfRawData_MSDTC_DistributedTransactionCoordinator Win32_PerfRawData_NETFramework_NETCLRExceptions Win32_PerfRawData_NETFramework_NETCLRInterop Win32_PerfRawData_NETFramework_NETCLRJit Win32_PerfRawData_NETFramework_NETCLRLoading Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads Win32_PerfRawData_NETFramework_NETCLRMemory Win32_PerfRawData_NETFramework_NETCLRRemoting Win32_PerfRawData_NETFramework_NETCLRSecurity Win32_PerfRawData_NTDS_NTDS Win32_PerfRawData_NTFSDRV_SMTPNTFSStoreDriver Win32_PerfRawData_PerfDisk_LogicalDisk Win32_PerfRawData_PerfDisk_PhysicalDisk Win32_PerfRawData_PerfNet_Browser Win32_PerfRawData_PerfNet_Redirector Win32_PerfRawData_PerfNet_Server Win32_PerfRawData_PerfNet_ServerWorkQueues Win32_PerfRawData_PerfOS_Cache "
$Words3 = $Words3 + "Win32_PerfRawData_PerfOS_Memory Win32_PerfRawData_PerfOS_Objects Win32_PerfRawData_PerfOS_PagingFile Win32_PerfRawData_PerfOS_Processor Win32_PerfRawData_PerfOS_System Win32_PerfRawData_PerfProc_FullImage_Costly Win32_PerfRawData_PerfProc_Image_Costly Win32_PerfRawData_PerfProc_JobObject Win32_PerfRawData_PerfProc_JobObjectDetails Win32_PerfRawData_PerfProc_Process Win32_PerfRawData_PerfProc_ProcessAddressSpace_Costly Win32_PerfRawData_PerfProc_Thread Win32_PerfRawData_PerfProc_ThreadDetails_Costly Win32_PerfRawData_RemoteAccess_RASPort Win32_PerfRawData_RemoteAccess_RASTotal Win32_PerfRawData_RSVP_ACSPerRSVPService Win32_PerfRawData_RSVP_ACSRSVPInterfaces Win32_PerfRawData_RSVP_ACSRSVPService Win32_PerfRawData_SMTPSVC_SMTPServer Win32_PerfRawData_Spooler_PrintQueue Win32_PerfRawData_TapiSrv_Telephony Win32_PerfRawData_Tcpip_ICMP Win32_PerfRawData_Tcpip_ICMPv6 Win32_PerfRawData_Tcpip_IP Win32_PerfRawData_Tcpip_IPv4 Win32_PerfRawData_Tcpip_IPv6 Win32_PerfRawData_Tcpip_NBTConnection Win32_PerfRawData_Tcpip_NetworkInterface Win32_PerfRawData_Tcpip_TCP Win32_PerfRawData_Tcpip_TCPv4 Win32_PerfRawData_Tcpip_TCPv6 Win32_PerfRawData_Tcpip_UDP Win32_PerfRawData_Tcpip_UDPv4 Win32_PerfRawData_Tcpip_UDPv6 Win32_PerfRawData_TermService_TerminalServices Win32_PerfRawData_TermService_TerminalServicesSession Win32_PerfRawData_W3SVC_WebService Win32_PhysicalMedia Win32_PhysicalMemory Win32_PhysicalMemoryArray Win32_PhysicalMemoryLocation Win32_PingStatus Win32_PNPAllocatedResource Win32_PnPDevice Win32_PnPEntity Win32_PnPSignedDriver Win32_PnPSignedDriverCIMDataFile Win32_PointingDevice Win32_PortableBattery Win32_PortConnector Win32_PortResource Win32_POTSModem Win32_POTSModemToSerialPort Win32_Printer Win32_PrinterConfiguration Win32_PrinterController Win32_PrinterDriver Win32_PrinterDriverDll Win32_PrinterSetting Win32_PrinterShare Win32_PrintJob Win32_Process Win32_Processor Win32_ProductOptional Win32_ProductCheck Win32_ProductResource Win32_ProductSoftwareFeatures Win32_ProgIDSpecification Win32_ProgramGroup Win32_ProgramGroupContents Win32_Property Win32_ProtocolBinding Win32_Proxy Win32_PublishComponentAction Win32_QuickFixEngineering Win32_QuotaSetting Win32_Refrigeration Win32_Registry Win32_RegistryAction Win32_RemoveFileAction Win32_RemoveIniAction Win32_ReserveCost Win32_ScheduledJob Win32_SCSIController Win32_SCSIControllerDevice Win32_SecuritySettingOfLogicalFile Win32_SecuritySettingOfLogicalShare Win32_SelfRegModuleAction Win32_SerialPort Win32_SerialPortConfiguration Win32_SerialPortSetting Win32_ServerConnection Win32_ServerSession Win32_Service Win32_ServiceControl Win32_ServiceSpecification Win32_ServiceSpecificationService Win32_SessionConnection Win32_SessionProcess Win32_ShadowBy Win32_ShadowCopy Win32_ShadowDiffVolumeSupport Win32_ShadowFor Win32_ShadowOn Win32_ShadowProvider Win32_ShadowStorage Win32_ShadowVolumeSupport Win32_Share Win32_ShareToDirectory Win32_ShortcutAction Win32_ShortcutFile Win32_ShortcutSAP Win32_SID Win32_SoftwareElement Win32_SoftwareElementAction Win32_SoftwareElementCheck Win32_SoftwareElementCondition Win32_SoftwareElementResource Win32_SoftwareFeature Win32_SoftwareFeatureAction Win32_SoftwareFeatureCheck Win32_SoftwareFeatureParent Win32_SoftwareFeatureSoftwareElements Win32_SoundDevice Win32_StartupCommand Win32_SubDirectory Win32_SystemAccount Win32_SystemBIOS Win32_SystemBootConfiguration Win32_SystemDesktop Win32_SystemDevices Win32_SystemDriver Win32_SystemDriverPNPEntity Win32_SystemEnclosure Win32_SystemLoadOrderGroups Win32_SystemLogicalMemoryConfiguration Win32_SystemNetworkConnections Win32_SystemOperatingSystem Win32_SystemPartitions Win32_SystemProcesses Win32_SystemProgramGroups Win32_SystemResources Win32_SystemServices Win32_SystemSlot Win32_SystemSystemDriver Win32_SystemTimeZone Win32_SystemUsers Win32_TapeDrive Win32_TCPIPPrinterPort Win32_TemperatureProbe Win32_Terminal Win32_TerminalService Win32_TerminalServiceSetting Win32_TerminalServiceToSetting Win32_TerminalTerminalSetting Win32_Thread Win32_TimeZone Win32_TSAccount Win32_TSClientSetting Win32_TSEnvironmentSetting Win32_TSGeneralSetting Win32_TSLogonSetting Win32_TSNetworkAdapterListSetting Win32_TSNetworkAdapterSetting Win32_TSPermissionsSetting Win32_TSRemoteControlSetting  Win32_TSSessionDirectory Win32_TSSessionDirectorySetting Win32_TSSessionSetting Win32_TypeLibraryAction Win32_UninterruptiblePowerSupply Win32_USBController Win32_USBControllerDevice Win32_USBHub Win32_UserAccount Win32_UserDesktop Win32_UserInDomain Win32_UTCTime Win32_VideoConfiguration Win32_VideoController Win32_VideoSettings Win32_VoltageProbe Win32_Volume Win32_VolumeQuota Win32_VolumeQuotaSetting Win32_VolumeUserQuota Win32_WindowsProductActivation Win32_WMIElementSetting Win32_WMISetting"
$KeywordsTextNode8 = $XmlDocument.CreateTextNode($Words3)
$Null = $KeywordsNode8.AppendChild($KeywordsTextNode8)

$KeywordsNode9 = $XmlDocument.CreateElement("Keywords")
$KeywordsAttribute = $KeywordsNode9.SetAttribute("name","Words4")
$Words4 = @'
$ $$ $? $^ $Args $DebugPreference $Error $ErrorActionPreference $false $foreach $HistorySize $HOME $Host $Input $LastExitCode $Match $MshHome $MyInvocation $null $OFS $PSCommandPath $ShellID $StackTrace $true $_
'@
$KeywordsTextNode9 = $XmlDocument.CreateTextNode($Words4)
$Null = $KeywordsNode9.AppendChild($KeywordsTextNode9)

$Null = $KeywordListsNode.AppendChild($KeywordsNode1)
$Null = $KeywordListsNode.AppendChild($KeywordsNode2)
$Null = $KeywordListsNode.AppendChild($KeywordsNode3)
$Null = $KeywordListsNode.AppendChild($KeywordsNode4)
$Null = $KeywordListsNode.AppendChild($KeywordsNode5)
$Null = $KeywordListsNode.AppendChild($KeywordsNode6)
$Null = $KeywordListsNode.AppendChild($KeywordsNode7)
$Null = $KeywordListsNode.AppendChild($KeywordsNode8)
$Null = $KeywordListsNode.AppendChild($KeywordsNode9)
$Null = $UserLangNode.AppendChild($KeywordListsNode)

$StylesNode = $XmlDocument.CreateElement("Styles")

$WordsStyleNode1 = $XmlDocument.CreateElement("WordsStyle")
$WordsStyleAttribute1 = $WordsStyleNode1.SetAttribute("name","DEFAULT")
$WordsStyleAttribute1 = $WordsStyleNode1.SetAttribute("fontStyle","0")
$WordsStyleAttribute1 = $WordsStyleNode1.SetAttribute("fontName","")
$WordsStyleAttribute1 = $WordsStyleNode1.SetAttribute("bgColor","FFFFFF")
$WordsStyleAttribute1 = $WordsStyleNode1.SetAttribute("fgColor","000000")
$WordsStyleAttribute1 = $WordsStyleNode1.SetAttribute("styleID","11")

$WordsStyleNode2 = $XmlDocument.CreateElement("WordsStyle")
$WordsStyleAttribute2 = $WordsStyleNode2.SetAttribute("name","FOLDEROPEN")
$WordsStyleAttribute2 = $WordsStyleNode2.SetAttribute("fontStyle","0")
$WordsStyleAttribute2 = $WordsStyleNode2.SetAttribute("fontName","")
$WordsStyleAttribute2 = $WordsStyleNode2.SetAttribute("bgColor","FFFFFF")
$WordsStyleAttribute2 = $WordsStyleNode2.SetAttribute("fgColor","000000")
$WordsStyleAttribute2 = $WordsStyleNode2.SetAttribute("styleID","12")

$WordsStyleNode3 = $XmlDocument.CreateElement("WordsStyle")
$WordsStyleAttribute3 = $WordsStyleNode3.SetAttribute("name","FOLDERCLOSE")
$WordsStyleAttribute3 = $WordsStyleNode3.SetAttribute("fontStyle","0")
$WordsStyleAttribute3 = $WordsStyleNode3.SetAttribute("fontName","")
$WordsStyleAttribute3 = $WordsStyleNode3.SetAttribute("bgColor","FFFFFF")
$WordsStyleAttribute3 = $WordsStyleNode3.SetAttribute("fgColor","000000")
$WordsStyleAttribute3 = $WordsStyleNode3.SetAttribute("styleID","13")

$WordsStyleNode4 = $XmlDocument.CreateElement("WordsStyle")
$WordsStyleAttribute4 = $WordsStyleNode4.SetAttribute("name","KEYWORD1")
$WordsStyleAttribute4 = $WordsStyleNode4.SetAttribute("fontStyle","0")
$WordsStyleAttribute4 = $WordsStyleNode4.SetAttribute("fontName","")
$WordsStyleAttribute4 = $WordsStyleNode4.SetAttribute("bgColor","FFFFFF")
$WordsStyleAttribute4 = $WordsStyleNode4.SetAttribute("fgColor","0000FF")
$WordsStyleAttribute4 = $WordsStyleNode4.SetAttribute("styleID","5")

$WordsStyleNode5 = $XmlDocument.CreateElement("WordsStyle")
$WordsStyleAttribute5 = $WordsStyleNode5.SetAttribute("name","KEYWORD2")
$WordsStyleAttribute5 = $WordsStyleNode5.SetAttribute("fontStyle","0")
$WordsStyleAttribute5 = $WordsStyleNode5.SetAttribute("fontName","")
$WordsStyleAttribute5 = $WordsStyleNode5.SetAttribute("bgColor","FFFFFF")
$WordsStyleAttribute5 = $WordsStyleNode5.SetAttribute("fgColor","8000FF")
$WordsStyleAttribute5 = $WordsStyleNode5.SetAttribute("styleID","6")

$WordsStyleNode6 = $XmlDocument.CreateElement("WordsStyle")
$WordsStyleAttribute6 = $WordsStyleNode6.SetAttribute("name","KEYWORD3")
$WordsStyleAttribute6 = $WordsStyleNode6.SetAttribute("fontStyle","0")
$WordsStyleAttribute6 = $WordsStyleNode6.SetAttribute("fontName","")
$WordsStyleAttribute6 = $WordsStyleNode6.SetAttribute("bgColor","FFFFFF")
$WordsStyleAttribute6 = $WordsStyleNode6.SetAttribute("fgColor","FF00FF")
$WordsStyleAttribute6 = $WordsStyleNode6.SetAttribute("styleID","7")

$WordsStyleNode7 = $XmlDocument.CreateElement("WordsStyle")
$WordsStyleAttribute7 = $WordsStyleNode7.SetAttribute("name","KEYWORD4")
$WordsStyleAttribute7 = $WordsStyleNode7.SetAttribute("fontStyle","0")
$WordsStyleAttribute7 = $WordsStyleNode7.SetAttribute("fontName","")
$WordsStyleAttribute7 = $WordsStyleNode7.SetAttribute("bgColor","FFFFFF")
$WordsStyleAttribute7 = $WordsStyleNode7.SetAttribute("fgColor","FF4500")
$WordsStyleAttribute7 = $WordsStyleNode7.SetAttribute("styleID","8")

$WordsStyleNode8 = $XmlDocument.CreateElement("WordsStyle")
$WordsStyleAttribute8 = $WordsStyleNode8.SetAttribute("name","COMMENT")
$WordsStyleAttribute8 = $WordsStyleNode8.SetAttribute("fontStyle","0")
$WordsStyleAttribute8 = $WordsStyleNode8.SetAttribute("fontName","")
$WordsStyleAttribute8 = $WordsStyleNode8.SetAttribute("bgColor","FFFFFF")
$WordsStyleAttribute8 = $WordsStyleNode8.SetAttribute("fgColor","006400")
$WordsStyleAttribute8 = $WordsStyleNode8.SetAttribute("styleID","1")

$WordsStyleNode9 = $XmlDocument.CreateElement("WordsStyle")
$WordsStyleAttribute9 = $WordsStyleNode9.SetAttribute("name","COMMENT LINE")
$WordsStyleAttribute9 = $WordsStyleNode9.SetAttribute("fontStyle","0")
$WordsStyleAttribute9 = $WordsStyleNode9.SetAttribute("fontName","")
$WordsStyleAttribute9 = $WordsStyleNode9.SetAttribute("bgColor","FFFFFF")
$WordsStyleAttribute9 = $WordsStyleNode9.SetAttribute("fgColor","006400")
$WordsStyleAttribute9 = $WordsStyleNode9.SetAttribute("styleID","2")

$WordsStyleNode10 = $XmlDocument.CreateElement("WordsStyle")
$WordsStyleAttribute10 = $WordsStyleNode10.SetAttribute("name","NUMBER")
$WordsStyleAttribute10 = $WordsStyleNode10.SetAttribute("fontStyle","0")
$WordsStyleAttribute10 = $WordsStyleNode10.SetAttribute("fontName","")
$WordsStyleAttribute10 = $WordsStyleNode10.SetAttribute("bgColor","FFFFFF")
$WordsStyleAttribute10 = $WordsStyleNode10.SetAttribute("fgColor","800080")
$WordsStyleAttribute10 = $WordsStyleNode10.SetAttribute("styleID","4")

$WordsStyleNode11 = $XmlDocument.CreateElement("WordsStyle")
$WordsStyleAttribute11 = $WordsStyleNode11.SetAttribute("name","OPERATOR")
$WordsStyleAttribute11 = $WordsStyleNode11.SetAttribute("fontStyle","0")
$WordsStyleAttribute11 = $WordsStyleNode11.SetAttribute("fontName","")
$WordsStyleAttribute11 = $WordsStyleNode11.SetAttribute("bgColor","FFFFFF")
$WordsStyleAttribute11 = $WordsStyleNode11.SetAttribute("fgColor","a9a9a9")
$WordsStyleAttribute11 = $WordsStyleNode11.SetAttribute("styleID","10")

$WordsStyleNode12 = $XmlDocument.CreateElement("WordsStyle")
$WordsStyleAttribute12 = $WordsStyleNode12.SetAttribute("name","DELIMINER1")
$WordsStyleAttribute12 = $WordsStyleNode12.SetAttribute("fontStyle","0")
$WordsStyleAttribute12 = $WordsStyleNode12.SetAttribute("fontName","")
$WordsStyleAttribute12 = $WordsStyleNode12.SetAttribute("bgColor","FFFFFF")
$WordsStyleAttribute12 = $WordsStyleNode12.SetAttribute("fgColor","8b0000")
$WordsStyleAttribute12 = $WordsStyleNode12.SetAttribute("styleID","14")

$WordsStyleNode13 = $XmlDocument.CreateElement("WordsStyle")
$WordsStyleAttribute13 = $WordsStyleNode13.SetAttribute("name","DELIMINER2")
$WordsStyleAttribute13 = $WordsStyleNode13.SetAttribute("fontStyle","0")
$WordsStyleAttribute13 = $WordsStyleNode13.SetAttribute("fontName","")
$WordsStyleAttribute13 = $WordsStyleNode13.SetAttribute("bgColor","FFFFFF")
$WordsStyleAttribute13 = $WordsStyleNode13.SetAttribute("fgColor","000000")
$WordsStyleAttribute13 = $WordsStyleNode13.SetAttribute("styleID","15")

$WordsStyleNode14 = $XmlDocument.CreateElement("WordsStyle")
$WordsStyleAttribute14 = $WordsStyleNode14.SetAttribute("name","DELIMINER3")
$WordsStyleAttribute14 = $WordsStyleNode14.SetAttribute("fontStyle","0")
$WordsStyleAttribute14 = $WordsStyleNode14.SetAttribute("fontName","")
$WordsStyleAttribute14 = $WordsStyleNode14.SetAttribute("bgColor","FFFFFF")
$WordsStyleAttribute14 = $WordsStyleNode14.SetAttribute("fgColor","000000")
$WordsStyleAttribute14 = $WordsStyleNode14.SetAttribute("styleID","16")

$Null = $StylesNode.AppendChild($WordsStyleNode1)
$Null = $StylesNode.AppendChild($WordsStyleNode2)
$Null = $StylesNode.AppendChild($WordsStyleNode3)
$Null = $StylesNode.AppendChild($WordsStyleNode4)
$Null = $StylesNode.AppendChild($WordsStyleNode5)
$Null = $StylesNode.AppendChild($WordsStyleNode6)
$Null = $StylesNode.AppendChild($WordsStyleNode7)
$Null = $StylesNode.AppendChild($WordsStyleNode8)
$Null = $StylesNode.AppendChild($WordsStyleNode9)
$Null = $StylesNode.AppendChild($WordsStyleNode10)
$Null = $StylesNode.AppendChild($WordsStyleNode11)
$Null = $StylesNode.AppendChild($WordsStyleNode12)
$Null = $StylesNode.AppendChild($WordsStyleNode13)
$Null = $StylesNode.AppendChild($WordsStyleNode14)

$Null = $UserLangNode.AppendChild($StylesNode)

$Null = $RootNode.AppendChild($UserLangNode)
$Null = $XmlDocument.AppendChild($RootNode)
$XmlDocument.Save($ExportFilePath)

$NewContent = Get-Content $ExportFilePath | Foreach-Object {$_ -replace "&", "&" -replace "<", "<" -replace ">", ">"} 
$NewContent | Set-Content $ExportFilePath

Aktualna wersja powyższego kodu znajduje się w repozytorium Git pod tym linkiem: NppPowershellLanguageSupport.ps1.

Microsoft Office Visio 2007

Cóż, pod koniec tego etapu przygotowawczego pozostaje zainstalować Edytor diagramów dla systemu Windows: Microsoft Office Visio 2007 Professional x86. Będzie to wymagało obrazu tej wersji produktu: en_office_visio_professional_2007_cd_x12-19212.iso. Obraz jest zapisywany na płycie i znajduje się w napędzie. Instalacja automatyczna wymaga małego pliku .xml z kilkoma parametrami.

<?xml version="1.0"?>
<Configuration Product="Professional">
  <Display Level="None" CompletionNotice="no" SuppressModal="yes" AcceptEula="yes" />
  <PIDKEY Value="12345-ABCDE-67890-FGHIJ-KLMNO" />
</Configuration>

Za pomocą poniższego kodu PowerShell utworzymy ten plik i przeprowadzimy automatyczną instalację. Ponadto w poniższym kodzie znajdują się ustawienia, które wyłączają wygląd okna dialogowego powitania przy pierwszym uruchomieniu pakietu Microsoft Office.

#######################################################################
#
# Powershell script for Silent Deploy Microsoft Visio 2007 Professional
#
# Script for Silent Deploy Microsoft Visio 2007 Professional.
# Script create xml file Acme.xml in $env:TEMP directory.
# Then script run Microsoft Visio 2007 Professional Setup.exe
# from en_office_visio_professional_2007_cd_x12-19212.iso with 
# parameter /Config $env:TEMP\Acme.xml.
# Afrer Silent Deploy file Acme.xml in $env:TEMP directory will be delete.
#  
# Version:        0.1
# Author:         Andrii Romanenko
# Website:        blogs.airra.net
# Creation Date:  12.09.2007
# Purpose/Change: Initial script development
#
# Run:
#   
# .\MsVisio2007ProSilentDeploy.ps1
#
#######################################################################

# Create Acme.xml in $env:TEMP directory.
$ExportFilePath = "$env:TEMP\Acme.xml"
$ProductKey = "12345-ABCDE-67890-FGHIJ-KLMNO"

$XmlDocument = New-Object System.Xml.XmlDocument
$xmlDeclaration = $XmlDocument.CreateXmlDeclaration("1.0",$Null,$Null)
$Null = $XmlDocument.AppendChild($xmlDeclaration)
$RootNode = $XmlDocument.CreateElement("Configuration")
$RootNodeAttribute = $RootNode.SetAttribute("Product","Professional")

$DisplayNode = $XmlDocument.CreateElement("Display")
$DisplayAttribute = $DisplayNode.SetAttribute("Level","None")
$DisplayAttribute = $DisplayNode.SetAttribute("CompletionNotice","no")
$DisplayAttribute = $DisplayNode.SetAttribute("SuppressModal","yes")
$DisplayAttribute = $DisplayNode.SetAttribute("AcceptEula","yes")

$PIDKEYNode = $XmlDocument.CreateElement("PIDKEY")
$PIDKEYAttribute = $PIDKEYNode.SetAttribute("Value",$ProductKey)

$Null = $RootNode.AppendChild($DisplayNode)
$Null = $RootNode.AppendChild($PIDKEYNode)
$Null = $XmlDocument.AppendChild($RootNode)
$XmlDocument.Save($ExportFilePath)

# Begin Silent Deploy Microsoft Visio 2007 Professional
$Message = "Begin Silent Setup Microsoft Visio 2007 Professional"
Write-Host -ForegroundColor Green $Message

$ISOPath = "E:\" 
$Params = " /config " + $env:TEMP + "\Acme.xml" 
$Command = $ISOPath + "Setup.exe" + $Params

Invoke-Expression $Command 
 
Write-Host "." -NoNewline
Start-Sleep -Seconds 60

# Checking if the application installation was successful 
Do {
         Write-Host "." -NoNewline
         Start-Sleep -Seconds 10
    } Until(Get-EventLog -LogName Application -Newest 10 | Where-Object {$_.Message -Like "*Microsoft Office Visio Professional 2007*Installation*successfully*"})

$Message = "`nSilent Setup Microsoft Visio 2007 Professional Succesfully!"
Write-Host -ForegroundColor Green $Message

# Disable the Office 2007 Welcome screen
Set-Location HKCU:
New-Item -Path "Software\Microsoft\Office\12.0\Common\" -Name "General" | Out-Null
New-ItemProperty -Path "Software\Microsoft\Office\12.0\Common\General" -Name "ShownOptIn" -Value 00000001 -PropertyType DWORD | Out-Null

$Message = "`nDisable the Office 2007 Welcome screen Succesfully!"
Write-Host -ForegroundColor Green $Message

#Removing Acme.xml
Set-Location c:
Remove-Item -Path ($env:TEMP+ "\Acme.xml") -Force

$Message = "`nRemoving Acme.xml Succesfully!"
Write-Host -ForegroundColor Green $Message

Aktualna wersja powyższego kodu znajduje się w repozytorium Git pod tym linkiem: MsVisio2007ProSilentDeploy.ps1.

Krótkie podsumowanie

Ponieważ wszystkie niezbędne narzędzia są już zainstalowane, możesz przejść do najciekawszego etapu: Pracy z Visio ze środowiska PowerShell.

Ale to zostanie omówione w następnej publikacji.

Do zobaczenia za kilka dni.
Z poważaniem, AIRRA!

Zaszufladkowano do kategorii Architektura, Kod, Programowanie, Projekt | Otagowano , , , , , , , , , , , , , , | Dodaj komentarz

Microsoft System Center Virtual Machine Manager 2007 – Podstawa zwirtualizowanego centrum danych. Wstęp. Lista artykułów.

 

Wstęp


Pozdrowienia dla wszystkich!

Andrey Romanenko, inżynier systemów, jest na antenie.

Tą wiadomością postanowiłem rozpocząć cykl artykułów o technologiach Microsoft System Center Virtual Machine Manager 2007. Od opisu ogólnego, po architekturę, etapy wdrażania i zastosowanie. Rozważmy osobno aspekty projektowania, rozmiar niezbędny do zademonstrowania funkcjonalności w postaci stoiska demonstracyjnego. Nie ignorujmy tematu integracji z innymi komponentami rozwiązania Microsoft System Center.

Równolegle trwają prace nad koncepcją i cyklem artykułów pod roboczym tytułem „Architektura i Design. Kod i programowanie”. Podejście to opiera się na technologiach automatyzacji na wszystkich etapach cyklu życia systemu informatycznego: Architektury i Projektowania, Wdrażania i Wdrożenia, Eksploatacji. I zgodnie z tym ideologicznym planem, te zmiany będą miały miejsce również w tej serii artykułów.

Dlatego postaramy się zautomatyzować wszystkie nasze kroki za pomocą technologii Microsoft Powershell lub API.

Przekaz ten będzie miał również formę katalogu artykułów, swego rodzaju encyklopedycznego punktu wejścia w temat produktu.

Jestem pewien, że będzie to interesujące i pouczające!
Do zobaczenia w wirtualnym centrum edukacji!
Z całym szacunkiem, Andrey.

Lista artykułów


Microsoft System Center Virtual Machine Manager 2007 – Podstawa zwirtualizowanego centrum danych:

Część 1. Wprowadzenie.

W tym artykule przedstawimy nowy produkt w portfolio firmy Microsoft – System Center Virtual Machine Manager. Poznaj jego główne cechy w kierunku zarządzania infrastrukturą wirtualną. Przyjrzyjmy się pokrótce głównemu elementowi sterującemu tego systemu – konsoli administratora. Wspomnijmy o systemach, z którymi będzie współdziałać Virtual Machine Manager. [Czytaj więcej]

Zaszufladkowano do kategorii Microsoft, Retrospektywa, Technologia, Wirtualizacja | Otagowano , , , , , , , | Dodaj komentarz