Public/Get-P1AdapterParameters.ps1

function Get-P1AdapterParameters {
    <#
    .Synopsis
    Get the adapter parameters.
 
    .Description
    Get the adapter parameters for tenant.
 
    .Parameter Tenant
    The target tenant.
    #>

    
    [cmdletbinding()]
    param( 
        [Parameter(Mandatory=$true)]
        [string] $Tenant
    )
    Process
    {
        if (!(Test-Tenant $Tenant)) {
            Write-Warning "Tenant $Tenant does not exist."
            Write-Warning "Operation canceled."
            return
        }

        $tenantInfo = Get-TenantInfo $Tenant
        if ($tenantInfo -eq $null) {
                Write-Warning "No tenant information available"
                Write-Warning "Configuration cancel"
                return
        }

        $Adapter = $tenantInfo.Adapter
        
        [string] $path = ""
        if ($Adapter -eq "NAV") {
            $path = Get-NAVConfigurationPath $Tenant
        }

        if ($Adapter -eq "REST") {
            $path = Get-RESTConfigurationPath $Tenant
        }

        if ($path -ne "") {
            Write-Verbose "Trying to read parameters in $path"
            if (Test-Path $path) {
                [string] $json = Get-Content $path
                if ($json -ne $null) {
                    $parameters = ConvertFrom-JSon $json
                    return $parameters
                } else {
                    Write-Warning "No configuration"
                    return $null
                }
            } else {
                Write-Warning "No configuration"
                return $null
            }
        } else {
            Write-Warning "No adapter type define for tenant"
            return $null
        }
    }
}