Private/Get-GraphImage.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function Get-GraphImage {
    Param(
        [Alias("GraphRoot")]
        $root,
        [Alias("GraphMiddle")]
        $middle, 
        [Alias("GraphLeaf")]
        $leaf,
        [Alias("BasePathToGraphImage")]
        $pathToImage
    )

    $imagePath = Join-Path -Path $pathToImage -ChildPath "$middle.png"
    $graphTMP=$null
    if ($null -eq $root) #not have boss
    {
        $graphTMP = graph g {
            edge -From $middle -To $leaf
        }    
    }
    elseif ($null -eq $leaf) #not have employees below
    {
        $graphTMP = graph g {
            edge -From $root -To $middle
        } 
    }
    else #have boss and employees
    {
        $graphTMP = graph g {
                    edge -From $root -To $middle
                    edge -From $middle -To $leaf
                }
    }
    
    $vizPath = Join-Path -Path $pathToImage -ChildPath "$middle.vz"
    Set-Content -Path $vizPath -Value $graphTMP
    Export-PSGraph -Source $vizPath -Destination $imagePath

    #cleaning
    Remove-Item -Path $vizPath

    $imagePath
}