Example 1

This is a simple example demonstrating how to create a 3-tier web application diagram using the PSGraph module, without using any object icons.

PowerShell: param block
[CmdletBinding()]
param (
    [System.IO.FileInfo] $Path = '~\Desktop\',
    [array] $Format = @('png'),
    [bool] $DraftMode = $false
)

Starting with PowerShell v3, modules are auto-imported when needed. Importing the module here ensures clarity and avoids ambiguity.

PowerShell
Import-Module Diagrammer.Core -Force -Verbose:$false

Since the diagram output is a file, specify the output folder path using $OutputFolderPath.

PowerShell
$OutputFolderPath = Resolve-Path $Path

The $MainGraphLabel variable sets the main title of the diagram.

PowerShell
$MainGraphLabel = '3tier Web Application Diagram'

This block creates a diagram with three servers, each represented by a custom node label and shape (without object icons).

Example1.ps1 - Node cmdlet
1
2
3
4
5
6
7
8
9
$example1 = & {

    # The Node function creates nodes with specified attributes, including custom labels and shapes.


    Node -Name Web01 -Attributes @{Label = 'Web01'; shape = 'rectangle'; fillColor = 'Green'; fontsize = 14 }
    Node -Name App01 -Attributes @{Label = 'App01'; shape = 'rectangle'; fillColor = 'Blue'; fontsize = 14 }
    Node -Name DB01 -Attributes @{Label = 'DB01'; shape = 'rectangle'; fillColor = 'Red'; fontsize = 14 }
}

Finally, call the New-Diagrammer cmdlet with the specified parameters.

PowerShell
New-Diagrammer -InputObject $example1 -OutputFolderPath $OutputFolderPath -Format $Format -MainDiagramLabel $MainGraphLabel -Filename Example1 -LogoName "Main_Logo"  -DraftMode:$DraftMode

The parameters used in the New-Diagrammer cmdlet are explained below:

Parameters Explained:
-InputObject: Accepts the custom object defined above.
-OutputFolderPath: Specifies where to save the generated diagram.
-Format: Sets the output format (png, jpg, svg, etc.).
-ImagesObj: Passes a hashtable of images for custom icons.
-MainDiagramLabel: Sets the diagram's title.
-Filename: Specifies the output file name (without extension).
-LogoName: Selects an image from the hashtable to use as the diagram logo.
    - If the specified logo image is not found, a default no_icon.png is used.
-DraftMode: If set to $true, generates a draft version of the diagram for troubleshooting.

When you run the script, it generates a PNG file named Example1.png in the specified output folder.

Resulting diagram:

Example

Comments