Public/CloudFactory/Add-CFExternalService.ps1

function Add-CFExternalService {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [PSCustomObject]$CustomerObject,

        [Parameter(Mandatory)]
        [ValidateSet('ACRONIS')]
        [string]$ServiceName,

        [Parameter(Mandatory = $true)]
        [string]$Uuid
    )

    try {
        if ($CustomerObject.externalServices.$ServiceName) {
            Write-ModuleLog -Message "External service $ServiceName already exists for customer $($CustomerObject.name). Skipping addition." -Level Verbose -Component 'CloudFactoryExternalServices'
            throw [System.Exception]::new("External service $ServiceName already exists for customer $($CustomerObject.name).")
        }

        Add-Member -InputObject $CustomerObject.externalServices -NotePropertyName $ServiceName -NotePropertyValue $Uuid
        $result = Update-CFCustomer -CustomerId $CustomerObject.id -Payload $CustomerObject
        return $result
    }
    catch {
        Write-ModuleLog -Message "Failed to add external service $ServiceName with UUID $Uuid to customer $($CustomerObject.name) in CloudFactory API." -Level Error -Component 'CloudFactoryExternalServices' -ErrorRecord $_
        throw
    }

}