functions/public/Save-KlippyKlippyLog.ps1
|
function Save-KlippyKlippyLog { <# .SYNOPSIS Downloads the Klipper log file from a printer. .DESCRIPTION Convenience function to download the klippy.log file. Automatically adds timestamps to the filename for archival. This is a wrapper around Save-KlippyLogFile for the Klipper 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-KlippyKlippyLog Downloads klippy.log from the default printer with timestamp. .EXAMPLE Save-KlippyKlippyLog -PrinterName "voronv2" -Destination "C:\logs\" Downloads to specific folder. .EXAMPLE Get-KlippyPrinter | Save-KlippyKlippyLog -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 = "klippy.log" Destination = $Destination } if ($NoTimestamp) { $saveParams['NoTimestamp'] = $true } if ($Force) { $saveParams['Force'] = $true } if ($PassThru) { $saveParams['PassThru'] = $true } if ($PSCmdlet.ShouldProcess("$($printer.PrinterName):logs/klippy.log", "Download Klipper log")) { Save-KlippyLogFile @saveParams } } } |