Private/Get-TLCollector.ps1

function Get-TLCollector {
    <#
    .SYNOPSIS
        Loads collector plugin descriptors from the Collectors folder.
    #>

    [CmdletBinding()]
    param(
        [string[]]$Name
    )

    $collectorPath = Join-Path -Path $script:TLModuleRoot -ChildPath 'Collectors'
    if (-not (Test-Path -Path $collectorPath)) { return }

    foreach ($file in (Get-ChildItem -Path $collectorPath -Filter '*.ps1' -File | Sort-Object -Property Name)) {
        $descriptor = $null
        try {
            $descriptor = & ([scriptblock]::Create((Get-Content -Path $file.FullName -Raw)))
        }
        catch {
            Write-Warning ("Collector '{0}' could not be loaded: {1}" -f $file.Name, $_.Exception.Message)
            continue
        }
        if ($null -eq $descriptor -or -not $descriptor['Name'] -or -not $descriptor['Collect']) {
            Write-Warning ("Collector '{0}' is missing the mandatory Name or Collect key - ignored." -f $file.Name)
            continue
        }
        if ($Name -and @($Name).Count -gt 0 -and ($Name -notcontains $descriptor['Name'])) { continue }

        $collectorName = [string]$descriptor['Name']
        [pscustomobject]@{
            Name           = $collectorName
            FileName       = $(if ($descriptor['FileName']) { [string]$descriptor['FileName'] }
                else { $collectorName.Substring(0, 1).ToLowerInvariant() + $collectorName.Substring(1) })
            ApiVersion     = $(if ($descriptor['ApiVersion']) { [string]$descriptor['ApiVersion'] } else { 'v1.0' })
            RequiredScopes = @($descriptor['RequiredScopes'] | Where-Object { $_ })
            Description    = [string]$descriptor['Description']
            Collect        = [scriptblock]$descriptor['Collect']
            Source         = $file.FullName
        }
    }
}