Deployment Snippet

ZIP-Dateien mit Logging kontrolliert entpacken.

Archive im Deployment wirken harmlos, sind aber oft Quelle fuer defekte Pfade, bereits vorhandene Reste oder unklare Entpackziele. Ein kleines Logging-Snippet spart hier spaeter viel Zeit.

PowerShell
function Expand-ZipWithLog {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory)] [string]$ZipPath,
        [Parameter(Mandatory)] [string]$Destination,
        [Parameter(Mandatory)] [string]$LogFile
    )

    try {
        if (-not (Test-Path -LiteralPath $Destination)) {
            New-Item -Path $Destination -ItemType Directory -Force | Out-Null
        }

        Expand-Archive -LiteralPath $ZipPath -DestinationPath $Destination -Force
        Write-Log -Path $LogFile -Component 'Archive' -Type Info -Message "Archiv entpackt: $ZipPath -> $Destination"
    }
    catch {
        Write-Log -Path $LogFile -Component 'Archive' -Type Error -Message "Archiv konnte nicht entpackt werden: $ZipPath. $($_.Exception.Message)"
        throw
    }
}