BCInstall/Get-BCFile.ps1
<#
.Synopsis Creates Business Central Install folder .Description Downloads requested version and creates Business Central install folder .Parameter installPath Path for BC install folder .Parameter version Defines version of BC to use. If empty, latest version will be used .Parameter country Defines the country version to use. If not provided, the NA version will be used (since always on premise) .Example Get-BCFile .Example Get-BCFile -installPath 'C:\' -version '16.3' -country 'na' #> function Get-BCFil { Param( [Parameter(Mandatory = $false)] [String] $installPath = 'C:\Installs', [Parameter(Mandatory = $false)] [String] $version = '', [Parameter(Mandatory = $false)] [String] $country = 'na' ) if ($version -eq '') { $artifactsUrl = Get-BCArtifactUrl -type OnPrem -country $country -select latest } else { $artifactsUrl = Get-BCArtifactUrl -type OnPrem -version $version -country $country -select latest } if ($null -eq $artifactsUrl -or $artifactsUrl -eq '') { Write-Error 'Could not find the proper artifacts' } $artifactPaths = Get-BCArtifact -artifactUrl $artifactsUrl -includePlatform $appArtifactPath = $artifactPaths[0] $platformArtifactPath = $artifactPaths[1] $appManifestPath = Join-Path $appArtifactPath "manifest.json" $appManifest = Get-Content $appManifestPath | ConvertFrom-Json $appVersion = $appManifest.version $appCountry = $appManifest.country $navDvdPath = Join-Path $installPath "NAVDVD_${appVersion}_${appCountry}" if (!(Test-Path $navDvdPath -PathType Container)) { New-Item $navDvdPath -ItemType Directory | Out-Null Write-Output "Copying Platform Artifacts" Get-ChildItem -Path $platformArtifactPath | ForEach-Object { if ($_.PSIsContainer) { Copy-Item -Path $_.FullName -Destination $navDvdPath -Recurse } else { Copy-Item -Path $_.FullName -Destination $navDvdPath } } "Installers", "ConfigurationPackages", "TestToolKit", "UpgradeToolKit", "Extensions", "Applications", "Applications.*" | ForEach-Object { $appSubFolder = Join-Path $appArtifactPath $_ if (Test-Path "$appSubFolder" -PathType Container) { $destFolder = Join-Path $navDvdPath $_ if (Test-Path $destFolder) { Remove-Item -Path $destFolder -Recurse -Force } Write-Output "Copy $_" Copy-Item -Path "$appSubFolder" -Destination $navDvdPath -Recurse } } } else { Write-Output "Folder NAVDVD_${appVersion}_${appCountry} already exists" } } Export-ModuleMember Get-BCFile |