Src/Private/Get-AbrVbrServiceProvider.ps1


function Get-AbrVbrServiceProvider {
    <#
    .SYNOPSIS
        Used by As Built Report to retrieve Veeam Cloud Service Providers
    .DESCRIPTION
        Documents the configuration of Veeam VBR in Word/HTML/Text formats using PScribo.
    .NOTES
        Version: 0.7.1
        Author: Jonathan Colon
        Twitter: @jcolonfzenpr
        Github: rebelinux
        Credits: Iain Brighton (@iainbrighton) - PScribo module
 
    .LINK
        https://github.com/AsBuiltReport/AsBuiltReport.Veeam.VBR
    #>

    [CmdletBinding()]
    param (

    )

    begin {
        Write-PscriboMessage "Discovering Veeam VBR Cloud Service Providers information from $System."
    }

    process {
        try {
            if ((Get-VBRInstalledLicense | Where-Object {$_.Edition -in @("EnterprisePlus")}) -and (Get-VBRCloudProvider).count -gt 0) {
                Section -Style Heading3 'Service Providers' {
                    Paragraph "The following section provides a summary about configured Veeam Cloud Service Providers."
                    BlankLine
                    try {
                        $CloudProviders = Get-VBRCloudProvider
                        $OutObj = @()
                        foreach ($CloudProvider in $CloudProviders) {
                            try {
                                Write-PscriboMessage "Discovered $($CloudProvider.DNSName) Service Provider summary information."
                                $inObj = [ordered] @{
                                    'DNS Name' = $CloudProvider.DNSName
                                    'Cloud Connect Type' = & {
                                        if ($CloudProvider.ResourcesEnabled -and $CloudProvider.ReplicationResourcesEnabled) {
                                            'BaaS & DRaaS'
                                        }
                                        elseif ($CloudProvider.ResourcesEnabled) {
                                            'BaaS'
                                        }
                                        elseif ($CloudProvider.ReplicationResourcesEnabled) {
                                            'DRaas'
                                        } else {'Unknown'}
                                    }
                                    'Managed By Provider' = ConvertTo-TextYN $CloudProvider.IsManagedByProvider
                                }
                                $OutObj += [pscustomobject]$inobj
                            }
                            catch {
                                Write-PscriboMessage -IsWarning "Service Providers $($CloudProvider.DNSName) Table: $($_.Exception.Message)"
                            }
                        }

                        $TableParams = @{
                            Name = "Service Providers - $VeeamBackupServer"
                            List = $false
                            ColumnWidths = 35, 35, 30
                        }

                        if ($Report.ShowTableCaptions) {
                            $TableParams['Caption'] = "- $($TableParams.Name)"
                        }
                        $OutObj | Sort-Object -Property 'DNS Name' | Table @TableParams
                        if ($InfoLevel.Infrastructure.ServiceProvider -ge 2) {
                            try {
                                Section -Style Heading4 'Service Providers Configuration' {
                                    foreach ($CloudProvider in $CloudProviders) {
                                        Section -Style Heading5 $CloudProvider.DNSName {
                                            try {
                                                Section -ExcludeFromTOC -Style NOTOCHeading6 'General Information' {
                                                    $OutObj = @()
                                                    Write-PscriboMessage "Discovered $($CloudProvider.DNSName) Service Provider general information."
                                                    $inObj = [ordered] @{
                                                        'DNS Name' = $CloudProvider.DNSName
                                                        'Ip Address' = $CloudProvider.IpAddress
                                                        'Port' = $CloudProvider.Port
                                                        'Credentials' = $CloudProvider.Credentials
                                                        'Certificate Expiration Date' = $CloudProvider.Certificate.NotAfter
                                                        'Managed By Service Provider' = ConvertTo-TextYN $CloudProvider.IsManagedByProvider
                                                        'Description'= $CloudProvider.Description
                                                    }

                                                    $OutObj = [pscustomobject]$inobj

                                                    $TableParams = @{
                                                        Name = "General Information - $($CloudProvider.DNSName)"
                                                        List = $true
                                                        ColumnWidths = 40, 60
                                                    }

                                                    if ($Report.ShowTableCaptions) {
                                                        $TableParams['Caption'] = "- $($TableParams.Name)"
                                                    }
                                                    $OutObj | Table @TableParams
                                                }
                                            }
                                            catch {
                                                Write-PscriboMessage -IsWarning "Service Providers General Information $($CloudProvider.DNSName) Table: $($_.Exception.Message)"
                                            }
                                            if ($CloudProvider.ResourcesEnabled) {
                                                try {
                                                    Section -ExcludeFromTOC -Style NOTOCHeading6 'BaaS Resources' {
                                                        $OutObj = @()
                                                        Write-PscriboMessage "Discovered $($CloudProvider.DNSName) Service Provider BaaS Resources information."
                                                        $inObj = [ordered] @{
                                                            'Resources Enabled' = ConvertTo-TextYN $CloudProvider.ResourcesEnabled
                                                            'Repository Name' = $CloudProvider.Resources.RepositoryName
                                                            'Wan Acceleration?' = $CloudProvider.Resources | ForEach-Object {"$($_.RepositoryName): $(ConvertTo-TextYN $_.WanAccelerationEnabled)"}
                                                            'Per Datastore Allocated Space' = $CloudProvider.Resources | ForEach-Object {"$($_.RepositoryName): $($_.RepositoryAllocatedSpace / 1024) GB"}
                                                            'Total Datastore Allocated Space' = "$([Math]::Round(($CloudProvider.Resources.RepositoryAllocatedSpace | measure-object -Sum).Sum / 1024)) GB"
                                                        }

                                                        $OutObj = [pscustomobject]$inobj

                                                        $TableParams = @{
                                                            Name = "BaaS Resources - $($CloudProvider.DNSName)"
                                                            List = $true
                                                            ColumnWidths = 40, 60
                                                        }

                                                        if ($Report.ShowTableCaptions) {
                                                            $TableParams['Caption'] = "- $($TableParams.Name)"
                                                        }
                                                        $OutObj | Table @TableParams
                                                    }
                                                }
                                                catch {
                                                    Write-PscriboMessage -IsWarning "Service Providers BaaS Resources $($CloudProvider.DNSName) Table: $($_.Exception.Message)"
                                                }
                                            }
                                            if ($CloudProvider.ReplicationResourcesEnabled) {
                                                try {
                                                    Section -ExcludeFromTOC -Style NOTOCHeading6 'DRaaS Resources' {
                                                        $OutObj = @()
                                                        $CPU = Switch ([string]::IsNullOrEmpty($CloudProvider.ReplicationResources.CPU)) {
                                                            $true {'Unlimited'}
                                                            $false {"$([math]::Round($CloudProvider.ReplicationResources.CPU / 1000, 1)) Ghz"}
                                                            default {'-'}
                                                        }
                                                        $Memory = Switch ([string]::IsNullOrEmpty($CloudProvider.ReplicationResources.Memory)) {
                                                            $true {'Unlimited'}
                                                            $false {"$([math]::Round($CloudProvider.ReplicationResources.Memory / 1Kb, 2)) GB"}
                                                            default {'-'}
                                                        }
                                                        Write-PscriboMessage "Discovered $($CloudProvider.DNSName) Service Provider DRaaS Resources information."
                                                        $inObj = [ordered] @{
                                                            'Resources Enabled' = ConvertTo-TextYN $CloudProvider.ReplicationResourcesEnabled
                                                            'Hardware Plan Name' = $CloudProvider.ReplicationResources.HardwarePlanName
                                                            'Allocated CPU Resources' = $CPU
                                                            'Allocated Memory Resources' = $Memory
                                                            'Repository Name' = $CloudProvider.ReplicationResources.Datastore.Name
                                                            'Per Datastore Allocated Space' = $CloudProvider.ReplicationResources.Datastore | ForEach-Object {"$($_.Name): $($_.DatastoreAllocatedSpace) GB"}
                                                            'Total Datastore Allocated Space' = "$([Math]::Round(($CloudProvider.ReplicationResources.Datastore.DatastoreAllocatedSpace | measure-object -Sum).Sum)) GB"
                                                            'Network Count' =  $CloudProvider.ReplicationResources.NetworkCount
                                                            'Public IP Enabled' = ConvertTo-TextYN $CloudProvider.ReplicationResources.PublicIpEnabled
                                                        }

                                                        if ($CloudProvider.ReplicationResources.PublicIpEnabled) {
                                                            $PublicIP = Switch ([string]::IsNullOrEmpty($CloudProvider.ReplicationResources.PublicIp)) {
                                                                $true {'-'}
                                                                $false {$CloudProvider.ReplicationResources.PublicIp}
                                                                default {'Unknown'}
                                                            }
                                                            $inObj.add('Allocated Public IP Address', $PublicIP)
                                                        }

                                                        $OutObj = [pscustomobject]$inobj

                                                        $TableParams = @{
                                                            Name = "DRaaS Resources - $($CloudProvider.DNSName)"
                                                            List = $true
                                                            ColumnWidths = 40, 60
                                                        }

                                                        if ($Report.ShowTableCaptions) {
                                                            $TableParams['Caption'] = "- $($TableParams.Name)"
                                                        }
                                                        $OutObj | Table @TableParams
                                                    }
                                                }
                                                catch {
                                                    Write-PscriboMessage -IsWarning "Service Providers DRaaS Resources $($CloudProvider.DNSName) Table: $($_.Exception.Message)"
                                                }
                                            }
                                            $DefaultGatewayConfig = Get-VBRDefaultGatewayConfiguration | Where-Object {$_.ProviderId -eq $CloudProvider.id}
                                            if ($DefaultGatewayConfig.DefaultGateway) {
                                                Section -ExcludeFromTOC -Style NOTOCHeading6 'Default Gateway' {
                                                    $OutObj = @()
                                                    foreach ($Gateway in $DefaultGatewayConfig.DefaultGateway) {
                                                        try {
                                                            Write-PscriboMessage "Discovered $($Gateway.Name) Service Provider Default Gateway information."
                                                            $inObj = [ordered] @{
                                                                'Name' = $Gateway.Name
                                                                'IP Address' = $Gateway.IpAddress
                                                                'Network Mask' = $Gateway.NetworkMask
                                                                'Routing Enabled?' = ConvertTo-TextYN $DefaultGatewayConfig.RoutingEnabled
                                                            }

                                                            $OutObj = [pscustomobject]$inobj

                                                            $TableParams = @{
                                                                Name = "Default Gateway - $($Gateway.Name)"
                                                                List = $true
                                                                ColumnWidths = 40, 60
                                                            }

                                                            if ($Report.ShowTableCaptions) {
                                                                $TableParams['Caption'] = "- $($TableParams.Name)"
                                                            }
                                                            $OutObj | Table @TableParams
                                                        }
                                                        catch {
                                                            Write-PscriboMessage -IsWarning "Service Providers $($Gateway.Name) Default Gateway Configuration Table: $($_.Exception.Message)"
                                                        }
                                                    }
                                                }
                                            }
                                            $CloudSubUserConfig = Get-VBRCloudSubUser | Where-Object {$_.CloudProviderId -eq $CloudProvider.id}
                                            if ($CloudSubUserConfig.DefaultGateway) {
                                                Section -ExcludeFromTOC -Style NOTOCHeading6 'Default Gateway' {
                                                    $OutObj = @()
                                                    foreach ($Gateway in $DefaultGatewayConfig.DefaultGateway) {
                                                        try {
                                                            Write-PscriboMessage "Discovered $($Gateway.Name) Service Provider Default Gateway information."
                                                            $inObj = [ordered] @{
                                                                'Name' = $Gateway.Name
                                                                'IP Address' = $Gateway.IpAddress
                                                                'Network Mask' = $Gateway.NetworkMask
                                                                'Routing Enabled?' = ConvertTo-TextYN $DefaultGatewayConfig.RoutingEnabled
                                                            }

                                                            $OutObj = [pscustomobject]$inobj

                                                            $TableParams = @{
                                                                Name = "Default Gateway - $($Gateway.Name)"
                                                                List = $true
                                                                ColumnWidths = 40, 60
                                                            }

                                                            if ($Report.ShowTableCaptions) {
                                                                $TableParams['Caption'] = "- $($TableParams.Name)"
                                                            }
                                                            $OutObj | Table @TableParams
                                                        }
                                                        catch {
                                                            Write-PscriboMessage -IsWarning "Service Providers $($Gateway.Name) Cloud SubUser Default Gateway Table: $($_.Exception.Message)"
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            catch {
                                Write-PscriboMessage -IsWarning "Service Providers Configuration Section: $($_.Exception.Message)"
                            }
                        }
                    }
                    catch {
                        Write-PscriboMessage -IsWarning "Service Providers Section: $($_.Exception.Message)"
                    }
                }
            }
        }
        catch {
            Write-PscriboMessage -IsWarning "Service Providers Document: $($_.Exception.Message)"
        }
    }
    end {}

}