Using PSGraph

PSGraph is an awesome free PowerShell library that you can use to visualize relationships. Before you can use PSGraph, you need to install its prerequisites (the graphviz engine). Both can be done if you have Administrator privileges:

#requires -RunAsAdministrator

# install prerequisite (graphviz)
Register-PackageSource -Name Chocolatey -ProviderName Chocolatey -Location
Find-Package graphviz | Install-Package -ForceBootstrap

# install PowerShell module
Install-Module -Name PSGraph

Once installed, here is how you can visualize object relationships:

$webServers = 'Web1','Web2','web3'
$apiServers = 'api1','api2'
$databaseServers = 'db1'

graph site1 {
    # External/DMZ nodes
    subgraph 0 -Attributes @{label='DMZ'} {
        node 'loadbalancer' @{shape='house'}
        rank $webServers
        node $webServers @{shape='rect'}
        edge 'loadbalancer' $webServers

    subgraph 1 -Attributes @{label='Internal'} {
        # Internal API servers
        rank $apiServers
        node $apiServers   
        edge $webServers -to $apiServers
        # Database Servers
        rank $databaseServers
        node $databaseServers @{shape='octagon'}
        edge $apiServers -to $databaseServers
} | Export-PSGraph -ShowGraph

The graph created in this example uses the hypothetical servers in the script file and attaches the appropriate relationships to them, then displays the image.

Twitter This Tip! ReTweet this Tip!

Comment on Using PSGraph

Yeppersgoodmodule.However,thereisnoreasontodothis… Register-PackageSource -Name Chocolatey -ProviderName Chocolatey -Location … if you are on PS4x oin Windows with PowerShellGet……/details.aspx … PSGet is already in PSV5+ on Windows…/about_packagemanagement   Find-Module -Name ‚*graph*’ | Format-Table -AutoSize Version Name Repository Description ——- —- ———- ———– … 2.1.21 PSGraph PSGallery Builds graph… … Though you can install btoh side by side on, it’s rather redundant in most cases.