Testing/Get-ContainerCompanyToTest.ps1

function Get-ContainerCompanyToTest {
    param(
        # Container to use
        [Parameter(Mandatory = $false)]
        [string]
        $ContainerName = (Get-ContainerFromLaunchJson)
    )

    [version]$BCFallPlatform = '15.0.0.0'
    [Version]$platform = [Version]::Parse((Get-AppKeyValue -SourcePath (Get-Location) -KeyName 'platform'))
    if ($platform -ge $BCFallPlatform) {
        $Companies = (New-WebServiceProxy ('http://{0}:7047/BC/WS/SystemService' -f (Get-NavContainerIpAddress $ContainerName)) -Credential (New-CredentialFromEnvironmentJson)).Companies()
    }
    else {
        $Companies = (New-WebServiceProxy ('http://{0}:7047/NAV/WS/SystemService' -f (Get-NavContainerIpAddress $ContainerName)) -Credential (New-CredentialFromEnvironmentJson)).Companies()
    }
    
    # there is a blank company in the Danish database - don't ask, I don't know
    if ((Get-NavContainerCountry $ContainerName) -eq 'dk') { 
        $CompanyName = $Companies.Item(1)
    }
    else {
        if ($null -eq $Companies.Count) {
            $CompanyName = $Companies
        }
        else {
            if ($Companies.Contains('CRONUS USA, Inc.')) {
                $CompanyName = 'CRONUS USA, Inc.'
            }
            else {
                $CompanyName = $Companies.Item(0)
            }
        }
    }

    $CompanyName
}

Export-ModuleMember -Function Get-ContainerCompanyToTest