Example 7
The Rank cmdlet (part of PSgraph module) is used in Graphviz to control the vertical or horizontal alignment of nodes. When you apply the Rank cmdlet to a set of nodes, it forces them to appear at the same level in the diagram—either in a row (horizontal alignment) or a column (vertical alignment).
For example, in a 3-tier architecture diagram, using the Rank cmdlet on App01 and DB01 ensures these nodes are visually grouped together at the same layer. This makes the diagram easier to read and helps clarify the relationships between components.
[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.
Since the diagram output is a file, specify the output folder path using $OutputFolderPath.
The $MainGraphLabel variable sets the main title of the diagram.
If the diagram uses custom icons, specify the path to the icons directory. This is a Graphviz requirement.
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. **
This section creates custom objects to hold server information, which are used to set node labels in the diagram.
$WebServerInfo = [PSCustomObject][ordered]@{
'OS' = 'Redhat Linux'
'Version' = '10'
'Build' = "10.1"
'Edition' = "Enterprise"
}
$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"
}
The Rank cmdlet is used to place nodes at the same hierarchical level.
https://psgraph.readthedocs.io/en/stable/Command-Rank-Advanced/
In this example, App01 and DB01 are aligned horizontally.
Finally, call the New-Diagrammer cmdlet with the specified parameters.
New-Diagrammer -InputObject $example7 -OutputFolderPath $OutputFolderPath -Format $Format -MainDiagramLabel $MainGraphLabel -Filename Example7 -LogoName "Main_Logo" -DraftMode:$DraftMode
When you run the script, it generates a PNG file named Example7.png in the specified output folder.
Resulting diagram: