functions/public/Save-KlippyMoonrakerLog.ps1
|
function Save-KlippyMoonrakerLog { <# .SYNOPSIS Downloads the Moonraker log file from a printer. .DESCRIPTION Convenience function to download the moonraker.log file. Automatically adds timestamps to the filename for archival. This is a wrapper around Save-KlippyLogFile for the Moonraker log. .PARAMETER Id The unique identifier of the printer. .PARAMETER PrinterName The friendly name of the printer. .PARAMETER InputObject A printer object from pipeline input. .PARAMETER Destination Local destination path. Can be a directory or full file path. Defaults to current directory. .PARAMETER NoTimestamp Disable automatic timestamp addition. .PARAMETER Force Overwrite existing local file without prompting. .PARAMETER PassThru Return the local FileInfo object. .EXAMPLE Save-KlippyMoonrakerLog Downloads moonraker.log from the default printer with timestamp. .EXAMPLE Save-KlippyMoonrakerLog -PrinterName "voronv2" -Destination "C:\logs\" Downloads to specific folder. .EXAMPLE Get-KlippyPrinter | Save-KlippyMoonrakerLog -Destination "./logs/" -PassThru Downloads from all printers and returns file objects. .OUTPUTS System.IO.FileInfo (when -PassThru is used). #> [CmdletBinding(DefaultParameterSetName = 'Default', SupportsShouldProcess = $true)] [OutputType([System.IO.FileInfo])] param( [Parameter(Mandatory = $true, ParameterSetName = 'ById')] [ValidateNotNullOrEmpty()] [string]$Id, [Parameter(Mandatory = $true, ParameterSetName = 'ByName')] [ValidateNotNullOrEmpty()] [string]$PrinterName, [Parameter(Mandatory = $true, ParameterSetName = 'ByObject', ValueFromPipeline = $true)] [PSCustomObject]$InputObject, [Parameter(Position = 0)] [string]$Destination = ".", [Parameter()] [switch]$NoTimestamp, [Parameter()] [switch]$Force, [Parameter()] [switch]$PassThru ) process { # Resolve printer $resolveParams = @{} switch ($PSCmdlet.ParameterSetName) { 'ById' { $resolveParams['Id'] = $Id } 'ByName' { $resolveParams['PrinterName'] = $PrinterName } 'ByObject' { $resolveParams['InputObject'] = $InputObject } } $printer = Resolve-KlippyPrinterTarget @resolveParams # Build parameters for Save-KlippyLogFile $saveParams = @{ Id = $printer.Id Path = "moonraker.log" Destination = $Destination } if ($NoTimestamp) { $saveParams['NoTimestamp'] = $true } if ($Force) { $saveParams['Force'] = $true } if ($PassThru) { $saveParams['PassThru'] = $true } if ($PSCmdlet.ShouldProcess("$($printer.PrinterName):logs/moonraker.log", "Download Moonraker log")) { Save-KlippyLogFile @saveParams } } } |