My DependsOn module will sort that
$data | Resolve-DependencyOrder -Key {$_.id} -DependsOn {$_.parentid}
My psgraph module will graph it
Graph {
Node
$data -nodescript {$_.id} @{label={$_.name}}
Edge
$data -fromscript {$_.parentid} -toscript {$_.id}
}