Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This is the script I created in this video https://youtu.be/2UnIFAWgEK0
$ContainerNameOld = 'BC17-dev'
$ContainerNameNew = 'BC18-dev'
$TargetVersionBasePath = 'C:\bcartifacts.cache\onprem\18.0.23013.23795'
$BackFolderName = 'C:\ProgramData\BcContainerHelper\DatabaseUpgrade\'
$BackFile17 = Join-Path $BackFolderName 'Database_17.bak'
# Unsinstall all Extensions
Get-BcContainerAppInfo -containerName $ContainerNameOld | ForEach-Object { UnInstall-BcContainerApp -containerName $ContainerNameOld -Name $_.Name -Version $_.Version -Force }
# Unintall all 'Symbols only' extensions
Get-BcContainerAppInfo -containerName $ContainerNameOld -SymbolsOnly | ForEach-Object { Unpublish-BcContainerApp -containerName $ContainerNameOld -Name $_.Name -Version $_.Version }
# Backup the database from docker container to docker host
Backup-BcContainerDatabases -containerName $ContainerNameOld -bakFolder $BackFolderName
#Stop the BC service in the target version container
Invoke-ScriptInBcContainer -containerName $ContainerNameNew -scriptblock {
Stop-NAVServerInstance -ServerInstance BC
}
# restore the database which should be upgraded to the target version docker container
Restore-DatabasesInBcContainer -containerName $ContainerNameNew -bakFile $BackFile17
Invoke-ScriptInBcContainer -containerName $ContainerNameNew -scriptblock {
$DatabaseName = 'Database_17'
Write-Host "Database conversion started"
Invoke-NAVApplicationDatabaseConversion -DatabaseServer localhost -DatabaseName $DatabaseName
Write-Host "Set the database name to point to the old version database"
Set-NAVServerConfiguration -ServerInstance BC -KeyName DatabaseName -KeyValue $DatabaseName
Write-Host "Disable the task scheduler"
Set-NavServerConfiguration -ServerInstance BC -KeyName "EnableTaskScheduler" -KeyValue false
Write-Host "Restart BC server instance"
Restart-NAVServerInstance -ServerInstance BC
# Technical upgrade only
# Get-NAVAppInfo -ServerInstance BC | Repair-NAVApp
# Restart-NAVServerInstance -ServerInstance BC
}
# Publish the new app versions
# If your target is not BC18 you need the adjust the path ####### here #######
Publish-BcContainerApp -containerName $ContainerNameNew -appFile (Join-Path $TargetVersionBasePath "\platform\ModernDev\program files\Microsoft Dynamics NAV\180\AL Development Environment\System.app") -PackageType SymbolsOnly
Publish-BcContainerApp -containerName $ContainerNameNew -appFile (Join-Path $TargetVersionBasePath "\de\Applications\System Application\Source\Microsoft_System Application.app")
Publish-BcContainerApp -containerName $ContainerNameNew -appFile (Join-Path $TargetVersionBasePath "\de\Applications\BaseApp\Source\Microsoft_Base Application.app")
Publish-BcContainerApp -containerName $ContainerNameNew -appFile (Join-Path $TargetVersionBasePath "\de\Applications\Application\Source\Microsoft_Application.app")
# Sync apps and start their data upgrade
Invoke-ScriptInBcContainer -containerName $ContainerNameNew -scriptblock {
$NewVersion = '18.0.23013.23795'
Sync-NAVTenant -ServerInstance BC -Tenant default -Mode Sync
Sync-NAVApp -ServerInstance BC -Tenant default -Name "System Application" -Version $NewVersion -Mode ForceSync
Sync-NAVApp -ServerInstance BC -Tenant default -Name "Base Application" -Version $NewVersion -Mode ForceSync
Sync-NAVApp -ServerInstance BC -Tenant default -Name "Application" -Version $NewVersion -Mode ForceSync
Start-NAVAppDataUpgrade -ServerInstance BC -Name "System Application" -Version $NewVersion
Start-NAVAppDataUpgrade -ServerInstance BC -Name "Base Application" -Version $NewVersion
}
# Lines 30 - 44 can be adapted to upgrade other MS extensions as well
# If you have custom extensions or other ISV or third party extensions you would want to upgrade them as well using these steps
# Get-BcContainerAppInfo -containerName $ContainerNameNew -SymbolsOnly
### After upgrade ###
Invoke-ScriptInBcContainer -containerName $ContainerNameNew -scriptblock {
Set-NavServerConfiguration -ServerInstance BC -KeyName "EnableTaskScheduler" -KeyValue true
Restart-NAVServerInstance -ServerInstance BC
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment