AL/Download-AppPackage.ps1
function Download-AppPackage { param ( [Parameter(Mandatory = $false)] [string]$Name, [Parameter(Mandatory = $false)] [string]$AppVersion, [Parameter(Mandatory = $false)] [int]$PlatformVersion = 0, [Parameter(Mandatory = $false)] [string]$LocalPath ) if ($PlatformVersion -eq 0) { if ([String]::IsNullOrEmpty($LocalPath)) { [version]$Platform = [Version]::Parse((Get-AppKeyValue -SourcePath (Get-Location) -KeyName 'platform')) } else { [version]$Platform = [Version]::Parse((Get-AppKeyValue -SourcePath $LocalPath -KeyName 'platform')) } $PlatformVersion = $Platform.Major } if ([String]::IsNullOrEmpty($Name)) { if ([String]::IsNullOrEmpty($LocalPath)) { $Name = Get-AppKeyValue -SourcePath (Get-Location) -KeyName name } else { $Name = Get-AppKeyValue -SourcePath $LocalPath -KeyName name } } if ([String]::IsNullOrEmpty($AppVersion)) { $Pattern = $Name } else { $Pattern = $Name + "_" + $AppVersion } do { $Path = "Business Central $PlatformVersion" Write-Verbose "Using pattern $Pattern to find app in path $Path" $FileName = Get-ChildItemFTPWinSCP $Path | Where-Object { $_ -match $Pattern } if ([String]::IsNullOrEmpty($FileName)) { $Path += '/Archive' $FileName = Get-ChildItemFTPWinSCP $Path | Where-Object { $_ -match $Pattern } } if (![String]::IsNullOrEmpty($FileName)) { break } $PlatformVersion--; } while ($PlatformVersion -ge 14) if ([String]::IsNullOrEmpty($FileName)){ return $null } if ($FileName.Count -gt 1) { $FileName = $FileName.Item($FileName.Count - 1) } if ([String]::IsNullOrEmpty($LocalPath)) { $LocalPath = Join-Path -Path (Get-Location) -ChildPath '.alpackages' } Write-Host "Downloading $Path/$FileName to $LocalPath" Get-ItemFTPWinSCP -FTPPath $Path -Name $FileName -LocalPath $LocalPath | Out-Null $VersionDownloaded = $FileName.Substring($FileName.LastIndexOf('_') + 1) $VersionDownloaded.Substring(0, $VersionDownloaded.LastIndexOf('.')) } Export-ModuleMember -Function Download-AppPackage |