Src/Private/Export-AbrVb365Diagram.ps1

function Export-AbrVb365Diagram {
    <#
    .SYNOPSIS
    Used by As Built Report to export Veeam VB365 infrastructure diagram
    .DESCRIPTION
        Documents the configuration of Veeam VB365 in Word/HTML/Text formats using PScribo.
    .NOTES
        Version: 0.4.0
        Author: Jonathan Colon
        Twitter: @jcolonfzenpr
        Github: rebelinux
        Credits: Iain Brighton (@iainbrighton) - PScribo module
 
    .LINK
        https://github.com/AsBuiltReport/AsBuiltReport.Veeam.VB365
    #>

    [CmdletBinding()]
    param (
    )

    begin {
        Write-PScriboMessage -Message "EnableDiagrams set to $($Options.EnableDiagrams)."
    }

    process {
        if ($Options.EnableDiagrams) {
            Write-PScriboMessage -Message 'Collecting Veeam Infrastructure diagram'

            # Variable translating Icon to Image Path ($IconPath)
            $script:Images = @{
                'VB365_Server' = 'Server.png'
                'VB365_Proxy_Server' = 'Server.png'
                'VB365_Proxy' = 'Proxy.png'
                'VBR_LOGO' = 'Veeam_logo_new.png'
                'VB365_LOGO_Footer' = 'verified_recoverability.png'
                'VB365_Repository' = 'VBO_Repository.png'
                'VB365_Windows_Repository' = 'Windows_Repository.png'
                'VB365_Object_Repository' = 'Object_storage.png'
                'VB365_Object_Support' = 'Object_storage.png'
                'Veeam_Repository' = 'VBR_Repository.png'
                'VB365_On_Premises' = 'Cluster.png'
                'VB365_Microsoft_365' = 'Cloud.png'
                'Microsoft_365' = 'Microsoft_Office_365.png'
                'Datacenter' = 'Datacenter.png'
                'VB365_Restore_Portal' = 'Web_console.png'
                'VB365_User_Group' = 'User_Group.png'
                'VB365_User' = 'User.png'
                'VBR365_Amazon_S3_Compatible' = 'S3_compatible_Storage.png'
                'VBR365_Amazon_S3' = 'AWS_S3.png'
                'VBR365_Azure_Blob' = 'Microsoft_Azure_Blob_Storage.png'
            }

            $RootPath = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent
            [System.IO.FileInfo]$IconPath = Join-Path $RootPath 'icons'

            $DiagramParams = @{
                'FileName' = 'AsBuiltReport.Veeam.VB365'
                'OutputFolderPath' = $OutputFolderPath
                'Direction' = 'top-to-bottom'
                'MainDiagramLabel' = 'Backup for Microsoft 365'
                'MainDiagramLabelFontsize' = 38
                'MainDiagramLabelFontcolor' = '#565656'
                'MainDiagramLabelFontname' = 'Segoe UI Black'
                'IconPath' = $IconPath
                'ImagesObj' = $Images
                'LogoName' = 'VBR_LOGO'
                'SignatureLogoName' = 'VB365_LOGO_Footer'
                'WaterMarkText' = $Options.DiagramWaterMark
            }

            if ($Options.DiagramTheme -eq 'Black') {
                $DiagramParams.add('MainGraphBGColor', 'Black')
                $DiagramParams.add('Edgecolor', 'White')
                $DiagramParams.add('Fontcolor', 'White')
                $DiagramParams.add('NodeFontcolor', 'White')
                $DiagramParams.add('WaterMarkColor', 'White')
            } elseif ($Options.DiagramTheme -eq 'Neon') {
                $DiagramParams.add('MainGraphBGColor', 'grey14')
                $DiagramParams.add('Edgecolor', 'gold2')
                $DiagramParams.add('Fontcolor', 'gold2')
                $DiagramParams.add('NodeFontcolor', 'gold2')
                $DiagramParams.add('WaterMarkColor', '#FFD700')
            } else {
                $DiagramParams.add('WaterMarkColor', 'DarkGreen')
            }

            if ($Options.ExportDiagrams) {
                if (-not $Options.ExportDiagramsFormat) {
                    $DiagramFormat = 'png'
                } else {
                    $DiagramFormat = $Options.ExportDiagramsFormat
                }
                $DiagramParams.Add('Format', $DiagramFormat)
            } else {
                $DiagramParams.Add('Format', 'base64')
            }

            if ($Options.EnableDiagramDebug) {

                $DiagramParams.Add('DraftMode', $True)

            }

            if ($Options.EnableDiagramSignature) {
                $DiagramParams.Add('Signature', $True)
                $DiagramParams.Add('AuthorName', $Options.SignatureAuthorName)
                $DiagramParams.Add('CompanyName', $Options.SignatureCompanyName)
            }

            if ($Options.ExportDiagrams) {
                try {
                    Write-PScriboMessage -Message 'Generating Veeam Infrastructure diagram'
                    $Graph = Get-AbrVb365Diagram
                    if ($Graph) {
                        Write-PScriboMessage -Message 'Saving Veeam Infrastructure diagram'
                        $Diagram = New-AbrDiagram @DiagramParams -InputObject $Graph -MainGraphLogoSizePercent 50 -DisableMainDiagramLogo
                        if ($Diagram) {
                            foreach ($OutputFormat in $DiagramFormat) {
                                Write-Information -MessageData "Saved 'AsBuiltReport.Veeam.VB365.$($OutputFormat)' diagram to '$($OutputFolderPath)'." -InformationAction Continue
                            }
                        }
                    }
                } catch {
                    Write-PScriboMessage -IsWarning -Message "Unable to export the Infrastructure Diagram: $($_.Exception.Message)"
                }
            }
            try {
                $DiagramParams.Remove('Format')
                $DiagramParams.Add('Format', 'base64')

                $Graph = Get-AbrVb365Diagram
                $Diagram = New-AbrDiagram @DiagramParams -InputObject $Graph -MainGraphLogoSizePercent 50 -DisableMainDiagramLogo
                if ($Diagram) {
                    $BestAspectRatio = Get-BestImageAspectRatio -GraphObj $Diagram -MaxWidth 600 -MaxHeight 600
                    Section -Style Heading2 'Infrastructure Diagram.' {
                        Image -Base64 $Diagram -Text 'Veeam Backup for Microsoft 365 Diagram' -Width $BestAspectRatio.Width -Height $BestAspectRatio.Height -Align Center
                    }
                }
            } catch {
                Write-PScriboMessage -IsWarning -Message "Unable to generate the Infrastructure Diagram: $($_.Exception.Message)"
            }
        }
    }

    end {}
}