|
1 | | -### What is this repository for? |
| 1 | +# PSGraph |
2 | 2 |
|
3 | | -The idea is to have a tool to analyze dependencies between objects in a scripted way. This module is a wrapper on [QuickGraph](https://github.com/YaccConstructor/QuickGraph), using its successor [QuikGraph](https://github.com/KeRNeLith/QuikGraph) library |
| 3 | +   |
4 | 4 |
|
5 | | -### Documentation |
6 | | -[Documentaion is here](https://github.com/eosfor/PSGraph/wiki) |
| 5 | +> **PSGraph is a PowerShell-first wrapper around the ⚡ QuickGraph / QuikGraph** ecosystem. |
| 6 | +> It lets you **build, query and visualise graphs directly from the pipeline** without |
| 7 | +> dropping down to C# or external tools. Think *LINQ for graphs* – but in PowerShell. |
7 | 8 |
|
8 | | -### Installation |
9 | | -```powershell code |
10 | | -Install-Module PSQuickGraph -Scope CurrentUser |
| 9 | +--- |
| 10 | + |
| 11 | +## Why another graph module? |
| 12 | + |
| 13 | +QuickGraph/QuikGraph gives .NET a battle-tested set of graph data-structures and algorithms (DFS, BFS, Dijkstra, min-cut, spanning-tree, etc.) :contentReference[oaicite:0]{index=0}. |
| 14 | +PSGraph layers **PowerShell ergonomics, discoverability and visualisation** on top so that: |
| 15 | + |
| 16 | +* You can **pipe any object collection** into a graph, specify what constitutes vertices |
| 17 | + and edges, and explore the relationships immediately. |
| 18 | +* Results stay as native objects – ideal for further CLI |
| 19 | + processing, reporting or automation. |
| 20 | + |
| 21 | +The original goal was to **analyse dependencies** in IaC workloads, but the module has proven handy for **network flows, security events, configuration drift** |
| 22 | + |
| 23 | +--- |
| 24 | + |
| 25 | +## Features at a glance |
| 26 | + |
| 27 | +| | What you get | |
| 28 | +|-----------------------------------|--------------| |
| 29 | +| **Idiomatic cmdlets** | `New-PSGraph`, `Add-PSVertex`, `Add-PSEdge`, `Get-GraphPath`, … | |
| 30 | +| **Ready-made algorithms** | All algorithms exposed by QuikGraph are one cmdlet away. | |
| 31 | +| **Batteries-included visualisation** | Render to GraphViz (`*.dot`, `png`, `svg`) or to JSON for Vega/D3 dashboards. | |
| 32 | +| **Pipeline-friendly** | Import/Export from CSV, JSON, XML, SQL, REST or live objects. | |
| 33 | +| **Test-driven** | Over 100 Pester tests ensure every cmdlet does what it says. | |
| 34 | +| **Cross-platform** | Runs anywhere PowerShell 7+ does (Windows, Linux, macOS). | |
| 35 | + |
| 36 | +--- |
| 37 | + |
| 38 | +## Quick install |
| 39 | + |
| 40 | +```powershell |
| 41 | +Install-Module -Name PSQuickGraph -Scope CurrentUser |
| 42 | +``` |
| 43 | + |
| 44 | +**An example of Cartesian layouts for a node-link diagram of hierarchical data.** |
| 45 | + |
| 46 | +```pwsh |
| 47 | +$data = (Invoke-WebRequest -Uri https://raw.githubusercontent.com/vega/vega-datasets/refs/heads/main/data/flare.json).Content | ConvertFrom-Json |
| 48 | +$index = [object[]]::new($data.count + 1) |
| 49 | +$data | % { $index[$_.id] = $_ } |
| 50 | +
|
| 51 | +$g = new-graph |
| 52 | +
|
| 53 | +$data | Group-Object -Property parent | % { |
| 54 | + $currentGroup = $_ |
| 55 | + if ([string]::IsNullOrEmpty($currentGroup.name)) { |
| 56 | + $currentGroup.Group | % { |
| 57 | + Add-Vertex -Vertex $_.name -Graph $g |
| 58 | + } |
| 59 | + } |
| 60 | + else { |
| 61 | + $parentLabel = $index[$currentGroup.name].name |
| 62 | + $currentGroup.Group | % { |
| 63 | + Add-Edge -From $parentLabel -To $_.name -Graph $g |
| 64 | + } |
| 65 | + } |
| 66 | +} |
| 67 | +
|
| 68 | +$tempDir = [System.IO.Path]::GetTempPath() |
| 69 | +$outFile = Join-Path $tempDir 'x.tree.html' |
| 70 | +Export-Graph -Graph $g -Format Vega_TreeLayout -Path $outFile |
| 71 | +``` |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | +**Same graph but woth Force Directed layout** |
| 77 | + |
| 78 | +```pwsh |
| 79 | +$tempDir = [System.IO.Path]::GetTempPath() |
| 80 | +$outFile = Join-Path $tempDir 'x.force.html' |
| 81 | +Export-Graph -Graph $g -Format Vega_ForceDirected -Path $outFile |
11 | 82 | ``` |
12 | | -### Usage examples |
13 | 83 |
|
14 | | -- [Visualizing traffic flow though Azure Firewall](https://azazello.darkcity.dev/sankey-d3/) |
15 | | -- [Visualizing Azure networking with graphs and d3js](https://azazello.darkcity.dev/azure-networking-d3js/) |
16 | | -- [Analyzing sysmon events with graph](https://azazello.darkcity.dev/graphs-windows-firewall/) |
| 84 | + |
0 commit comments