Private/Get-ADPDIntuneManagementExtension.ps1

function Get-ADPDIntuneManagementExtension {
    [CmdletBinding()]
    param()

    $programData = $env:ProgramData
    if ([string]::IsNullOrWhiteSpace($programData)) {
        $logPath = 'C:\ProgramData\Microsoft\IntuneManagementExtension\Logs'
    } else {
        $logPath = Join-Path -Path $programData -ChildPath 'Microsoft\IntuneManagementExtension\Logs'
    }

    $service = $null
    if (Get-Command -Name 'Get-Service' -ErrorAction SilentlyContinue) {
        $service = Get-Service -Name 'IntuneManagementExtension' -ErrorAction SilentlyContinue
    }
    $logFiles = @()

    if (Test-Path -Path $logPath) {
        $logFiles = @(Get-ChildItem -Path $logPath -File -ErrorAction SilentlyContinue |
                Where-Object { $_.Extension -eq '.log' } |
                Sort-Object LastWriteTime -Descending |
                Select-Object -First 20 |
                ForEach-Object {
                    [pscustomobject]@{
                        Name          = $_.Name
                        LastWriteTime = $_.LastWriteTime
                        SizeBytes     = $_.Length
                    }
                })
    }

    [pscustomobject]@{
        Installed   = $null -ne $service
        ServiceState = if ($service) { $service.Status.ToString() } else { $null }
        LogPath      = $logPath
        LogFiles     = $logFiles
    }
}