Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions PITCHME.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ PSGraph is a PowerShell module that allows you to script the generation of graph
![basic graph](https://kevinmarquette.github.io/img/basic.png)

---
### Install GraphViz from the Chocolatey repo

Register-PackageSource -Name Chocolatey -ProviderName Chocolatey -Location http://chocolatey.org/api/v2/
Find-Package graphviz | Install-Package -ForceBootstrap

### Install PSGraph from the Powershell Gallery

Expand All @@ -18,6 +14,12 @@ PSGraph is a PowerShell module that allows you to script the generation of graph

Import-Module PSGraph

### Install GraphViz
Install-GraphViz -Scope CurrentUser|AllUsers
# Note, a warning may be written if chocolatey is not installed.
# However, an older version of GraphViz will be used from nuget.org which should still work.
# If you see this warning, considering installing chocolatey and then re-running to have newer Graphviz

---

### Describe how items are connected
Expand Down Expand Up @@ -115,4 +117,4 @@ For more information

* [psgraph.readthedocs.io](http://psgraph.readthedocs.io)
* [github.com/kevinmarquette/psgraph](https://github.com/kevinmarquette/psgraph)
* [kevinmarquette.github.io](https://kevinmarquette.github.io)
* [kevinmarquette.github.io](https://kevinmarquette.github.io)
6 changes: 5 additions & 1 deletion PSGraph/PSGraph.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'PSGraph.psm1'

# Version number of this module.
ModuleVersion = '2.1.38'
ModuleVersion = '2.1.39'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -108,6 +108,10 @@

# ReleaseNotes of this module
ReleaseNotes = @'
2.1.39 20250318
* add support for non-admin install on Windows.
* gracefully handle systems without Chocolatey by falling back to nuget.org's 2016 Graphviz package.

2.1.16 20180217
* add Record command
* add Row command
Expand Down
3 changes: 2 additions & 1 deletion PSGraph/Public/Export-PSGraph.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function Export-PSGraph
[string[]]
$GraphVizPath = (
'C:\Program Files\NuGet\Packages\Graphviz*\dot.exe',
"$env:USERPROFILE\AppData\Local\PackageManagement\NuGet\Packages\Graphviz*\dot.exe", # The Install-GraphViz -Scope CurrentUser location.
'C:\program files*\GraphViz*\bin\dot.exe',
'/usr/local/bin/dot',
'/usr/bin/dot'
Expand All @@ -96,7 +97,7 @@ function Export-PSGraph
if ( $null -eq $graphViz )
{
$GraphvizPathString = $GraphVizPath -Join " or "
throw "Could not find GraphViz installed on this system. Please run 'Install-GraphViz' to install the needed binaries and libraries. This module just a wrapper around GraphViz and is looking for it in the following paths: $($GraphvizPathString). Optionally pass a path to your dot.exe file with the GraphVizPath parameter"
throw "Could not find GraphViz installed on this system. Please run 'Install-GraphViz' to install the needed binaries and libraries. Use 'Install-GraphViz -Scope CurrentUser' to install for the current user only on Windows. This module just a wrapper around GraphViz and is looking for it in the following paths: $($GraphvizPathString). Optionally pass a path to your dot.exe file with the GraphVizPath parameter"
}

$useStandardInput = $false
Expand Down
31 changes: 27 additions & 4 deletions PSGraph/Public/Install-GraphViz.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ function Install-GraphViz
Installs GraphViz package using online provider
.Example
Install-GraphViz
.PARAMETER Scope
Use -Scope CurrentUser to install as non-admin to appdata instead of program files.
Unused on *Nix systems.
#>
[cmdletbinding( SupportsShouldProcess = $true, ConfirmImpact = "High" )]
param()
param(
[ValidateSet('AllUsers', 'CurrentUser')]
[string]
$Scope = 'AllUsers'
)

process
{
Expand All @@ -24,12 +31,28 @@ function Install-GraphViz
{
if ( $PSCmdlet.ShouldProcess('Register Chocolatey provider and install graphviz' ) )
{
if ( -Not ( Get-PackageProvider | Where-Object ProviderName -eq 'Chocolatey' ) )
if ( -Not ( Get-PackageSource | Where-Object ProviderName -eq 'Chocolatey' ) )
{
Register-PackageSource -Name Chocolatey -ProviderName Chocolatey -Location http://chocolatey.org/api/v2/
try {
Register-PackageSource -Name Chocolatey -ProviderName Chocolatey -Location http://chocolatey.org/api/v2/ -ErrorAction 'Stop'
} catch {
# We can still install graphviz from nuget.org, though it is more outdated than the choco one.
# as of writing (March 2025) choco has 12.2.1* and nuget.org has 2.1.38.* from 2016 BUT it still works.
$nugetSource = Get-PackageSource | Where-Object { $_.Location -like 'https://api.nuget.org/v*' }
if (-not $nugetSource) {
Write-Warning 'No nuget.org feed found to fall back on. Cannot install graphviz.'
throw
}

Write-Warning '------------------------------------------------------------'
Write-Warning $_
Write-Warning 'Could not register a Chocolatey package provider. Will fall back to the older nuget.org Graphviz package instead.'
Write-Warning 'If you see this error, considering installing chocolatey and then re-running this command to use the latest Graphviz.'
Write-Warning '------------------------------------------------------------'
}
}

Find-Package graphviz | Install-Package -Verbose -ForceBootstrap
Find-Package graphviz | Install-Package -Verbose -ForceBootstrap -Scope $Scope
}
}
}
Expand Down
17 changes: 9 additions & 8 deletions docs/Quick-Start-Installation-and-Example.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Installing PSGraph
Make sure you are running Powershell 5.0 (WMF 5.0). I don't know that it is a hard requirement at the moment but I plan on using 5.0 features.

# Install GraphViz from the Chocolatey repo
Register-PackageSource -Name Chocolatey -ProviderName Chocolatey -Location http://chocolatey.org/api/v2/
Find-Package graphviz | Install-Package -ForceBootstrap
Make sure you are running Powershell 5.0 (WMF 5.0) or Powershell 7+ (pwsh.exe).

# Install PSGraph from the Powershell Gallery
Find-Module PSGraph | Install-Module
Find-Module PSGraph | Install-Module

# Install GraphViz
Install-GraphViz -Scope CurrentUser|AllUsers
# Note, a warning may be written if chocolatey is not installed.
# However, an older version of GraphViz will be used from nuget.org which should still work.
# If you see this warning, considering installing chocolatey and then re-running to have newer Graphviz


# Generating your first graph
Expand All @@ -18,10 +19,10 @@ PSGraph has a unique syntax for defining a graph. This is because it was built s
Import-Module PSGraph

graph "myGraph" {
edge start,middle,end
edge start,middle,end
} | Export-PSGraph -ShowGraph

This will create a new graph with three nodes linking each other.
This will create a new graph with three nodes linking each other.

[![Source](images/firstGraph.png)](images/firstGraph.png)

Expand Down
36 changes: 19 additions & 17 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![Build status](https://ci.appveyor.com/api/projects/status/cgo827o4f74lmf9w/branch/master?svg=true)](https://ci.appveyor.com/project/kevinmarquette/PSGraph/branch/master) [![Documentation Status](https://readthedocs.org/projects/psgraph/badge/?version=latest)](http://psgraph.readthedocs.io/en/latest/?badge=latest)


# PSGraph

Expand All @@ -19,7 +19,7 @@ PSGraph is a helper module implemented as a DSL (Domain Specific Language) for g
Beta release. The core module work and documentation is fleshed out. The simple features are implemented but there are other features of the DOT language that I have not used much myself. The command names and arguments of the existing commands should be stable now. As always, more testing still needs to be done.

# GraphViz and the Dot format basics
The nice thing about GraphViz is that you can define nodes and edges with a simple text file in the Dot format. The GraphViz engine handles the layout, edge routing, rendering and creates an image for you.
The nice thing about GraphViz is that you can define nodes and edges with a simple text file in the Dot format. The GraphViz engine handles the layout, edge routing, rendering and creates an image for you.

Here is a sample Dot file.

Expand Down Expand Up @@ -53,7 +53,7 @@ I tried to keep a syntax that was similar to GraphViz but offer the flexibility
## Graph or digraph
This is the container that holds graph elements. Every valid GraphViz graph has one. `digraph` is just an alias of `graph` so I am going to use the shorter `graph` for the rest of the readme.

graph g {
graph g {
}

## Edge
Expand All @@ -70,12 +70,12 @@ If you supply two arrays, it will cross multiply them. So each item on the left
graph g {
edge (1,3) (2,4)
}

Because this is Powershell, we can mix in normal commands. Take this example.

$folders = Get-ChildItem -Directory -Recurse
graph g {
$folders | %{edge $_.Name $_.Parent}
$folders | %{edge $_.Name $_.Parent}
}

I also support edge attributes that are defined in the DOT specification by using a hashtable.
Expand All @@ -99,8 +99,8 @@ This is the exact Dot output generated those node commands.

"start" [shape="house"]
"end" [shape="invhouse"]
"start"->"middle"
"middle"->"end"
"start"->"middle"
"middle"->"end"
}

## Rank
Expand Down Expand Up @@ -142,31 +142,33 @@ We can pull that all together and generate quite the data driven driven diagram.
subgraph 1 -Attributes @{label='Internal'} {
# Internal API servers
rank $apiServers
node $apiServers
node $apiServers
edge $webServers -to $apiServers

# Database Servers
rank $databaseServers
node $databaseServers @{shape='octagon'}
edge $apiServers -to $databaseServers
}
}
}



# Installing PSGraph
Make sure you are running Powershell 5.0 (WMF 5.0). I don't know that it is a hard requirement at the moment but I plan on using 5.0 features.

# Install GraphViz from the Chocolatey repo
Register-PackageSource -Name Chocolatey -ProviderName Chocolatey -Location http://chocolatey.org/api/v2/
Find-Package graphviz | Install-Package -ForceBootstrap
Make sure you are running Powershell 5.0 (WMF 5.0) or Powershell 7+ (pwsh.exe).

# Install PSGraph from the Powershell Gallery
Find-Module PSGraph | Install-Module

# Import Module
Import-Module PSGraph

# Install GraphViz
Install-GraphViz -Scope CurrentUser|AllUsers
# Note, a warning may be written if chocolatey is not installed.
# However, an older version of GraphViz will be used from nuget.org which should still work.
# If you see this warning, considering installing chocolatey and then re-running to have newer Graphviz

For OSX, you can use brew to install graphviz.

brew install graphviz
Expand All @@ -181,11 +183,11 @@ I am still working out the workflow for this, but for now just do this.

# Save to file
Set-Content -Path $env:temp\hello.vz -Value $dot

Export-PSGraph -Source $env:temp\hello.vz -Destination $env:temp\hello.png -ShowGraph

The export can be done more in line if needed.

graph g {
edge hello world
} | Export-PSGraph -ShowGraph
} | Export-PSGraph -ShowGraph