-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExample14.ps1
More file actions
244 lines (191 loc) · 12.4 KB
/
Example14.ps1
File metadata and controls
244 lines (191 loc) · 12.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# ** This time, we'll demonstrate the use of Add-NodeShape cmdlet to add custom shapes to the diagram (Part of AsBuiltReport.Diagram module). **
<#
This example demonstrates how to create a 3-tier web application diagram using the AsBuiltReport.Diagram.
#>
[CmdletBinding()]
param (
[System.IO.FileInfo] $Path = '~\Desktop\',
[array] $Format = @('png'),
[bool] $DraftMode = $false
)
<#
Starting with PowerShell v3, modules do not need to be explicitly imported.
It is included here for clarity.
#>
# Import-Module AsBuiltReport.Diagram -Force -Verbose:$false
<#
The diagram output is a file, so we need to specify the output folder path. In this example, $OutputFolderPath is used.
#>
$OutputFolderPath = Resolve-Path -Path $Path
<#
If the diagram uses custom icons, specify the path to the icons directory. This is a Graphviz requirement.
#>
$RootPath = $PSScriptRoot
[System.IO.FileInfo]$IconPath = Join-Path -Path $RootPath -ChildPath 'Icons'
<#
The $Images variable is a hashtable containing the names of image files used in the diagram.
The image files must be located in the directory specified by $IconPath.
** Image sizes should be around 100x100, 150x150 pixels for optimal display. **
#>
$script:Images = @{
'Main_Logo' = 'AsBuiltReport.png'
'Server' = 'Server.png'
'ServerRedhat' = 'Linux_Server_RedHat.png'
'ServerUbuntu' = 'Linux_Server_Ubuntu.png'
'Cloud' = 'Cloud.png'
'Router' = 'Router.png'
'Logo_Footer' = 'Signature_Logo.png'
}
<#
The $MainGraphLabel variable sets the main title of the diagram.
#>
$MainGraphLabel = 'Web Application Diagram'
<#
This section creates custom objects to hold server information, which are used to set node labels in the diagram.
#>
$AppServerInfo = [PSCustomObject][ordered]@{
'OS' = 'Windows Server'
'Version' = '2019'
'Build' = '17763.3163'
'Edition' = 'Datacenter'
}
$DBServerInfo = [PSCustomObject][ordered]@{
'OS' = 'Oracle Server'
'Version' = '8'
'Build' = '8.2'
'Edition' = 'Enterprise'
}
$example14 = & {
<#
A SubGraph allows you to group objects in a container, creating a graph within a graph.
SubGraph, Node, and Edge have attributes for setting background color, label, border color, style, etc.
(SubGraph is a reserved word in the PSGraph module)
https://psgraph.readthedocs.io/en/latest/Command-SubGraph/
#>
SubGraph 3tier -Attributes @{Label = '3 Tier Concept'; fontsize = 22; penwidth = 1.5; labelloc = 't'; style = 'dashed,rounded'; color = 'darkgray' } {
<#
The Add-HtmlSignatureTable cmdlet creates a signature table to be used as a footer in the diagram.
It can include images, author name, company name, and other details.
(Part of AsBuiltReport.Diagram module)
#>
$Signature = Add-HtmlSignatureTable -ImagesObj $Images -Rows 'Author: Bugs Bunny', 'Company: ACME Inc.' -TableBorder 2 -CellBorder 0 -Align 'left' -Logo 'Logo_Footer' -DraftMode:$DraftMode -FontBold
<#
The Signature SubGraph contains the $Signature table created above.
It is styled to be invisible and positioned at the bottom of the diagram.
The SubGraph attributes set the label, font size, pen width, label location, label justification, style, and color.
(Part of Graphviz attributes)
#>
SubGraph Signature -Attributes @{Label = $Signature; fontsize = 22; penwidth = 1.5; labelloc = 'b'; labeljust = 'right'; style = 'invis'; color = 'darkgray' } {
<#
The $WebServerFarm variable is an array of hashtables, each representing a web server node with its properties.
Each hashtable contains:
- Name: The name of the web server.
- AdditionalInfo: A custom object with properties to display in the node label.
- IconType: The type of icon to use for the node (must match a key in the $Images hashtable).
#>
$WebServerFarm = @(
@{
Name = 'Web-Server-01';
AdditionalInfo = [PSCustomObject][ordered]@{
'OS' = 'Redhat Linux'
'Version' = '10'
'Build' = '10.1'
'Edition' = 'Enterprise'
}
IconType = 'ServerRedhat'
},
@{
Name = 'Web-Server-02';
AdditionalInfo = [PSCustomObject][ordered]@{
'OS' = 'Redhat Linux'
'Version' = '10'
'Build' = '10.1'
'Edition' = 'Enterprise'
}
IconType = 'ServerRedhat'
},
@{
Name = 'Web-Server-03';
AdditionalInfo = [PSCustomObject][ordered]@{
'OS' = 'Ubuntu Linux'
'Version' = '24'
'Build' = '11'
'Edition' = 'Enterprise'
}
IconType = 'ServerUbuntu'
}
)
<#
This time, we will simulate a Web Server Farm with multiple web server node. While the Add-NodeIcon cmdlet is typically used to add icons/properties to nodes, it lack the ability to create multiple nodes with distinct properties.
Add-HtmlNodeTable has the capability to create a table layout for the nodes simulting a web server farm. It also allows the addition of icons and properties to each node in the table.
** The $Images object and IconType "Server" must be defined earlier in the script **
-MultiIcon parameter allows multiple icons to be displayed in the table. (IconType must be specified in the inputObject)
-iconType parameter sets the type of icon to use for the nodes. In this case the $WebServerFarm.IconType hashtable value is used
(must match a key in the $Images hashtable).
#>
Add-HtmlNodeTable -Name 'Web-Server-Farm' -ImagesObj $Images -inputObject $WebServerFarm.Name -iconType $WebServerFarm.IconType -ColumnSize 3 -AditionalInfo $WebServerFarm.AdditionalInfo -Subgraph -SubgraphLabel 'Web Server Farm' -SubgraphLabelPos 'top' -SubgraphTableStyle 'dashed,rounded' -TableBorderColor 'gray' -TableBorder '1' -SubgraphLabelFontSize 20 -FontSize 18 -DraftMode:$DraftMode -FontBold -SubgraphFontBold -NodeObject -MultiIcon
Add-NodeIcon -Name 'App-Server-01' -AditionalInfo $AppServerInfo -ImagesObj $Images -IconType 'Server' -Align 'Center' -FontSize 18 -DraftMode:$DraftMode -NodeObject
Add-NodeIcon -Name 'Db-Server-01' -AditionalInfo $DBServerInfo -ImagesObj $Images -IconType 'Server' -Align 'Center' -FontSize 18 -DraftMode:$DraftMode -NodeObject
<#
This section creates connections between the nodes in a hierarchical layout.
The Add-NodeEdge cmdlet creates connections between the nodes. (Part of AsBuiltReport.Diagram module)
https://github.com/AsBuiltReport/AsBuiltReport.Diagram
#>
Add-NodeEdge -From 'Web-Server-Farm' -To 'App-Server-01' -EdgeLabel 'gRPC' -EdgeColor 'black' -EdgeLabelFontSize 14 -EdgeLabelFontColor 'black' -EdgeLength 3 -EdgeThickness 3 -EdgeStyle 'dashed'
Add-NodeEdge -From 'App-Server-01' -To 'Db-Server-01' -EdgeLabel 'SQL' -EdgeColor 'black' -EdgeLabelFontSize 14 -EdgeLabelFontColor 'black' -EdgeLength 3 -EdgeThickness 3 -EdgeStyle 'dashed'
<#
The Rank cmdlet is used to place nodes at the same hierarchical level.
In this example, App-Server-01 and Db-Server-01 are aligned horizontally.
#>
Rank -Nodes 'App-Server-01', 'Db-Server-01'
<#
In this section, we add a network router and a cloud icon to represent internet connectivity.
#>
$RouterInfo = [PSCustomObject][ordered]@{
'OS' = 'Cisco IOS'
'Version' = '15.2'
}
Add-NodeIcon -Name 'Core-Router' -AdditionalInfo $RouterInfo -ImagesObj $Images -IconType 'Router' -Align 'Center' -FontSize 18 -DraftMode:$DraftMode -NodeObject
Add-NodeEdge -From 'Core-Router' -To 'Web-Server-Farm' -EdgeLabel 'GE0/0' -EdgeColor 'black' -EdgeLabelFontSize 18 -EdgeLabelFontColor 'black' -EdgeLength 2 -EdgeThickness 3 -EdgeStyle 'dashed'
<#
This section demonstrates the use of the Add-NodeImage to add a custom image to the diagram (Part of AsBuiltReport.Diagram module).
-Name parameter sets the name of the node (WAN in this case).
-ImageSizePercent parameter sets the size of the image as a percentage (30% in this case).
#>
Add-NodeImage -Name 'WAN' -ImagesObj $Images -IconType 'Cloud' -IconPath $IconPath -ImageSizePercent 30 -NodeObject -DraftMode:$DraftMode
<#
The Add-HtmlTable cmdlet is used to create a list table to display additional information about a object.
In this example, we create a table to display the router's network interface information.
#>
$RouterNetworkInfo = @(
'S0/0:'
'164.42.203.10/30'
'G0/0:'
'192.168.5.10/24'
)
Add-HtmlTable -Name 'RouterNetworkInfo' -Rows $RouterNetworkInfo -NodeObject -ColumnSize 2 -TableBorder 1 -TableBorderColor 'black' -FontSize 14 -Subgraph -SubgraphLabel 'Interfaces Table' -SubgraphLabelPos 'top' -SubgraphTableStyle 'solid,rounded' -SubgraphLabelFontsize 20 -SubgraphFontUnderline -SubgraphFontBold -DraftMode:$DraftMode -TableBackgroundColor 'lightblue'
Add-NodeEdge -From 'Core-Router' -To 'RouterNetworkInfo' -EdgeColor 'black' -EdgeLabelFontSize 18 -EdgeLabelFontColor 'black' -EdgeLength 1 -Arrowhead 'none' -Arrowtail 'none' -GraphvizAttributes @{style = 'filled' }
Rank 'Core-Router', 'RouterNetworkInfo'
<#
The Add-NodeShape cmdlet is used to create a node with a specific shape and various customizable attributes (Part of AsBuiltReport.Diagram module). Supported Shapes: https://graphviz.org/doc/info/shapes.html
-Shape parameter sets the shape of the node (rectangle in this case).
-ShapeStyle parameter sets the style of the shape (filled in this case).
-ShapeFillColor parameter sets the fill color of the shape (red:white (gradient) in this case).
-ShapeFontSize parameter sets the font size of the shape label (14 in this case
-ShapeFontColor parameter sets the font color of the shape label (white in this case).
-ShapeFontName parameter sets the font name of the shape label (Arial in this case
-ShapeWidth parameter sets the width of the shape (3 in this case).
-ShapeLabelPosition parameter sets the position of the label within the shape (center in this case).
-ShapeLineColor parameter sets the color of the shape's border (black in this case).
** In this example, we create a rectangle to simulate a firewall presence in the network. **
#>
Add-NodeShape -Name 'Firewall' -Shape rectangle -ShapeStyle 'filled' -ShapeFillColor 'red:white' -ShapeFontSize 14 -ShapeFontColor 'black' -ShapeFontName 'Arial' -ShapeWidth 3 -ShapeLabelPosition center -ShapeLineColor 'black' -DraftMode:$DraftMode
Add-NodeEdge -From 'WAN' -To 'Firewall' -HeadLabel 'port1' -EdgeColor 'black' -EdgeLabelFontSize 18 -EdgeLabelFontColor 'black' -EdgeLength 2 -Arrowhead 'normal' -Arrowtail 'normal' -LabelDistance 5 -EdgeThickness 3 -EdgeStyle 'dashed'
Add-NodeEdge -From 'Firewall' -To 'Core-Router' -HeadLabel 'Serial0/0' -TailLabel 'port2' -EdgeColor 'black' -EdgeLabelFontSize 18 -EdgeLabelFontColor 'black' -EdgeLength 2 -Arrowhead 'normal' -Arrowtail 'normal' -LabelDistance 4 -EdgeThickness 3 -EdgeStyle 'dashed'
}
}
}
<#
This command generates the diagram using the New-AbrDiagram cmdlet (part of AsBuiltReport.Diagram).
#>
New-AbrDiagram -InputObject $example14 -OutputFolderPath $OutputFolderPath -Format $Format -MainDiagramLabel $MainGraphLabel -Filename Example14 -LogoName 'Main_Logo' -Direction top-to-bottom -IconPath $IconPath -ImagesObj $Images -DraftMode:$DraftMode