Skip to content

Instantly share code, notes, and snippets.

@KiloNiner
KiloNiner / convert-bhgraph.ps1
Created May 2, 2024 15:25
Convert BloodHound graph files into CSV files
function Convert-BHGraph
{
<#
.SYNOPSIS
Convert BloodHound graph files into CSV files.
.DESCRIPTION
The PowerShell script Convert-BHGraph is designed to convert JSON files, specifically formatted as BloodHound graph exports, into CSV files. It accepts optional parameters for the source JSON file path and the destination CSV file path, defaulting to .\bh-graph.json and .\bh-graph.csv respectively. The script reads the JSON file, extracts nodes and edges data, and constructs a hashtable for nodes to facilitate quick lookups. It then processes the edges to create custom objects representing relationships, which include labels and kinds for both source and target nodes, as well as the type of edge. Finally, these relationship objects are exported to a CSV file at the specified destination path, providing a structured representation of the graph's relationships.
.EXAMPLE
Convert-BHGraph
Converts the file bh-graph.json from the current directory into a CSV file named bh-g