functions/public/Get-KlippyServerInfo.ps1

function Get-KlippyServerInfo {
    <#
    .SYNOPSIS
        Gets Moonraker server information from a Klipper printer.

    .DESCRIPTION
        Retrieves detailed information about the Moonraker server including
        version, API version, registered components, and connection status.

    .PARAMETER Id
        The unique identifier of the printer.

    .PARAMETER PrinterName
        The friendly name of the printer.

    .PARAMETER InputObject
        A printer object from pipeline input.

    .EXAMPLE
        Get-KlippyServerInfo
        Gets server info from the default printer.

    .EXAMPLE
        Get-KlippyServerInfo -PrinterName "voronv2"
        Gets server info from the specified printer.

    .EXAMPLE
        Get-KlippyPrinter | Get-KlippyServerInfo
        Gets server info from all registered printers.

    .OUTPUTS
        PSCustomObject with Moonraker server information.
    #>

    [CmdletBinding(DefaultParameterSetName = 'Default')]
    [OutputType([PSCustomObject])]
    param(
        [Parameter(Mandatory = $true, ParameterSetName = 'ById')]
        [ValidateNotNullOrEmpty()]
        [string]$Id,

        [Parameter(Mandatory = $true, ParameterSetName = 'ByName', Position = 0)]
        [ValidateNotNullOrEmpty()]
        [string]$PrinterName,

        [Parameter(Mandatory = $true, ParameterSetName = 'ByObject', ValueFromPipeline = $true)]
        [PSCustomObject]$InputObject
    )

    process {
        # Resolve printer
        $resolveParams = @{}
        switch ($PSCmdlet.ParameterSetName) {
            'ById' { $resolveParams['Id'] = $Id }
            'ByName' { $resolveParams['PrinterName'] = $PrinterName }
            'ByObject' { $resolveParams['InputObject'] = $InputObject }
        }

        $printer = Resolve-KlippyPrinterTarget @resolveParams

        try {
            Write-Verbose "[$($printer.PrinterName)] Fetching server info..."

            $serverInfo = Invoke-KlippyJsonRpc -Printer $printer -Method "server/info"

            [PSCustomObject]@{
                PSTypeName           = 'KlippyCLI.ServerInfo'
                PrinterId            = $printer.Id
                PrinterName          = $printer.PrinterName
                KlippyConnected      = $serverInfo.KlippyConnected
                KlippyState          = $serverInfo.KlippyState
                MoonrakerVersion     = $serverInfo.MoonrakerVersion
                ApiVersion           = $serverInfo.ApiVersion
                ApiVersionText       = $serverInfo.ApiVersionText
                Components           = $serverInfo.Components
                FailedComponents     = $serverInfo.FailedComponents
                RegisteredDirectories = $serverInfo.RegisteredDirectories
                Warnings             = $serverInfo.Warnings
            }
        }
        catch {
            Write-Error "[$($printer.PrinterName)] Failed to get server info: $_"
        }
    }
}