functions/dynamicsnav/Get-NAVServerPlatform.ps1

function Get-NAVServerPlatform {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)]
        [string]$ServerInstance
    )
    
    try {
        $ServiceName = "MicrosoftDynamicsNavServer`$$ServerInstance"
        if (-not ($service = Get-WmiObject Win32_Service -Filter "Name='$ServiceName'")) {
            Write-Error "Could not find service $($ServiceName)!"
            return $false
        }
        # TODO: check for Service\Installed=1
        if ($service.PathName -match '\\([^\\]+)\\Service\\') {
            $PlatformVersion = $matches[1]
            return $PlatformVersion
        } else {
            Write-Error "Could not parse platform version for service $($ServiceName)"
            return $false    
        }
    } catch {
        Write-Error "Could not query platform version for erver instance $($ServerInstance)! $_"
        return $false
    }
}