Functions/Extract-DatabaseFromZipFile.ps1
function Extract-DatabaseFromZipFile { [cmdletbinding()] Param ( [parameter(Mandatory=$true)] [string] $ZipFilePath ) PROCESS { Write-Verbose "Inspecting contents of artifact" [Void][Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem') if (Test-Path $ZipFilePath) { $zipFile = [IO.Compression.ZipFile]::OpenRead($ZipFilePath) $MyApp = $zipFile.Entries | Where-Object { $_.FullName -match '.bak' } $zipFile.Dispose() } else { Write-Error "$ZipFilePath File path not found" } if (!$MyApp) { throw "Cannot find the .app file in $ZipFilePath" } Write-Verbose "Extracting bak from artifact" $parent = [System.IO.Path]::GetTempPath() $name = [System.IO.Path]::GetRandomFileName() $ExtractFolder = Join-Path $parent $name if (Test-Path $ExtractFolder) { Remove-Item $ExtractFolder -Recurse -Force } [IO.Compression.ZipFile]::ExtractToDirectory($ZipFilePath, $ExtractFolder) $FullPath4PSConstructApp = Join-Path $ExtractFolder $MyApp.FullName $FullPath4PSConstructApp } } Export-ModuleMember -Function Extract-DatabaseFromZipFile |