Skip to content

Commit

Permalink
Freddydk/smallbugfixes (#3715)
Browse files Browse the repository at this point in the history
Small bugfixes:
- Wait for databases to be mounted when running
Restore-DatabasesInBcContainer
- Include AI Toolkit when copying symbols from container
- Issue 3714 Download-BcNuGetPackageToFolder - throws error when use
"-select Exact"
- Issue 3621 New-AadAppsForBc shows "-includeEmailAadApp is deprecated.
Use -includeOtherServicesAadApp instead." but includeOtherServicesAadApp
us not setting email permissions
- Issue 3718 Business Central Web Client Fails to Load After Updating to
Windows 24H2

Fixes #3714
Fixes #3621
Fixes #3718

---------

Co-authored-by: freddydk <[email protected]>
  • Loading branch information
freddydk and freddydk authored Oct 11, 2024
1 parent f95c2a5 commit 5d25208
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 278 deletions.
1 change: 0 additions & 1 deletion AzureAD/New-AadAppsForBc.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ try {

# EMail App
if ($IncludeEmailAadApp) {
Write-Host -ForegroundColor Yellow "-includeEmailAadApp is deprecated. Use -includeOtherServicesAadApp instead."
# Remove "old" Email AD Application
$EMailIdentifierUri = $appIdUri.Replace('://','://email.')
Get-MgApplication -All | Where-Object { $_.IdentifierUris -contains $EMailIdentifierUri } | ForEach-Object { Remove-MgApplication -ApplicationId $_.Id }
Expand Down
5 changes: 5 additions & 0 deletions Bacpac/Restore-DatabasesInNavContainer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ try {
}

Set-NavServerInstance -ServerInstance $serverInstance -start
$boo = $true
while (Get-NAVServerInstance | Get-NavTenant | Where-Object { $_.State -eq "Mounting" }) {
if ($boo) { Write-Host "Waiting for tenants to be mounted"; $boo = $false }
Start-Sleep -Seconds 1
}
}

} -argumentList $containerBakFolder, $containerBakFile, $databaseName, $tenant, $databaseFolder, $sqlTimeout
Expand Down
6 changes: 3 additions & 3 deletions BcContainerHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ if ($useVolumes -or $isInsideContainer) {
$bcContainerHelperConfig.UseVolumes = $true
}

$hypervState = ""
function Get-HypervState {
if ($isAdministrator -and $hypervState -eq "") {
$hypervState = "Unknown"
function GetHypervState {
if ($isAdministrator -and $hypervState -eq "Unknown") {
try {
$feature = Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V -Online
if ($feature) {
Expand Down
6 changes: 6 additions & 0 deletions ContainerHandling/Get-BestGenericImageName.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ function Get-BestGenericImageName {
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {

if ($LatestGenericTagVersion -eq '0.0.0.0') {
$labels = Get-BcContainerImageLabels -imageName 'mcr.microsoft.com/businesscentral:ltsc2022'
Write-Host "Setting LatestGenericTagVersion to $($labels.tag)"
$LatestGenericTagVersion = $labels.tag
}

if ($hostOsVersion -eq $null) {
$os = (Get-CimInstance Win32_OperatingSystem)
if ($os.OSType -ne 18 -or !$os.Version.StartsWith("10.0.")) {
Expand Down
201 changes: 9 additions & 192 deletions ContainerHandling/New-NavContainer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -421,77 +421,14 @@ try {
$UBR = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name UBR).UBR

$hostOsVersion = [System.Version]::Parse("$($os.Version).$UBR")
$hostOs = "Unknown/Insider build"
$bestGenericImageName = Get-BestGenericImageName -onlyMatchingBuilds -filesOnly:$filesOnly

$isServerHost = $os.ProductType -eq 3

if ($os.BuildNumber -eq 26100) {
$hostOs = "24H2"
}
elseif ($os.BuildNumber -eq 22631) {
$hostOs = "23H2"
}
elseif ($os.BuildNumber -eq 22621) {
$hostOs = "22H2"
}
elseif ($os.BuildNumber -eq 22000) {
$hostOs = "21H2"
}
elseif ($os.BuildNumber -eq 20348) {
$hostOs = "ltsc2022"
}
elseif ($os.BuildNumber -eq 19045) {
$hostOs = "22H2"
}
elseif ($os.BuildNumber -eq 19044) {
$hostOs = "21H2"
}
elseif ($os.BuildNumber -eq 19043) {
$hostOs = "21H1"
}
elseif ($os.BuildNumber -eq 19042) {
$hostOs = "20H2"
}
elseif ($os.BuildNumber -eq 19041) {
$hostOs = "2004"
}
elseif ($os.BuildNumber -eq 18363) {
$hostOs = "1909"
}
elseif ($os.BuildNumber -eq 18362) {
$hostOs = "1903"
}
elseif ($os.BuildNumber -eq 17763) {
if ($isServerHost) {
$hostOs = "ltsc2019"
}
else {
$hostOs = "1809"
}
}
elseif ($os.BuildNumber -eq 17134) {
$hostOs = "1803"
}
elseif ($os.BuildNumber -eq 16299) {
$hostOs = "1709"
}
elseif ($os.BuildNumber -eq 15063) {
$hostOs = "1703"
}
elseif ($os.BuildNumber -eq 14393) {
if ($isServerHost) {
$hostOs = "ltsc2016"
}
else {
$hostOs = "1607"
}
}
$hostOs = GetHostOs -hostOsVersion $hostOsVersion -isServerHost $isServerHost
$bestGenericImageName = Get-BestGenericImageName -onlyMatchingBuilds -filesOnly:$filesOnly

Write-Host "BcContainerHelper is version $BcContainerHelperVersion"
if ($isAdministrator) {
Write-Host "BcContainerHelper is running as administrator"
Write-Host "HyperV is $(Get-HypervState)"
Write-Host "HyperV is $(GetHypervState)"
}
else {
Write-Host "BcContainerHelper is not running as administrator"
Expand Down Expand Up @@ -1095,50 +1032,9 @@ try {
AddTelemetryProperty -telemetryScope $telemetryScope -key "genericTag" -value "$genericTag"

$containerOsVersion = [Version]"$($inspect.Config.Labels.osversion)"
if ("$containerOsVersion".StartsWith('10.0.14393.')) {
$containerOs = "ltsc2016"
if (!$useBestContainerOS -and $TimeZoneId -eq $null) {
$timeZoneId = (Get-TimeZone).Id
}
}
elseif ("$containerOsVersion".StartsWith('10.0.15063.')) {
$containerOs = "1703"
}
elseif ("$containerOsVersion".StartsWith('10.0.16299.')) {
$containerOs = "1709"
}
elseif ("$containerOsVersion".StartsWith('10.0.17134.')) {
$containerOs = "1803"
}
elseif ("$containerOsVersion".StartsWith('10.0.17763.')) {
$containerOs = "ltsc2019"
}
elseif ("$containerOsVersion".StartsWith('10.0.18362.')) {
$containerOs = "1903"
}
elseif ("$containerOsVersion".StartsWith('10.0.18363.')) {
$containerOs = "1909"
}
elseif ("$containerOsVersion".StartsWith('10.0.19041.')) {
$containerOs = "2004"
}
elseif ("$containerOsVersion".StartsWith('10.0.19042.')) {
$containerOs = "20H2"
}
elseif ("$containerOsVersion".StartsWith('10.0.19043.')) {
$containerOs = "21H1"
}
elseif ("$containerOsVersion".StartsWith('10.0.19044.')) {
$containerOs = "21H2"
}
elseif ("$containerOsVersion".StartsWith('10.0.19045.')) {
$containerOs = "22H2"
}
elseif ("$containerOsVersion".StartsWith('10.0.20348.')) {
$containerOs = "ltsc2022"
}
else {
$containerOs = "unknown"
$containerOs = GetContainerOs -containerOsVersion $containerOsVersion
if ($containerOs -eq 'ltsc2016' -and !$useBestContainerOS -and $TimeZoneId -eq $null) {
$timeZoneId = (Get-TimeZone).Id
}
Write-Host "Container OS Version: $containerOsVersion ($containerOs)"
Write-Host "Host OS Version: $hostOsVersion ($hostOs)"
Expand Down Expand Up @@ -1223,94 +1119,15 @@ try {
}

$containerOsVersion = [Version]"$($inspect.Config.Labels.osversion)"

if ("$containerOsVersion".StartsWith('10.0.14393.')) {
$containerOs = "ltsc2016"
}
elseif ("$containerOsVersion".StartsWith('10.0.15063.')) {
$containerOs = "1703"
}
elseif ("$containerOsVersion".StartsWith('10.0.16299.')) {
$containerOs = "1709"
}
elseif ("$containerOsVersion".StartsWith('10.0.17134.')) {
$containerOs = "1803"
}
elseif ("$containerOsVersion".StartsWith('10.0.17763.')) {
$containerOs = "ltsc2019"
}
elseif ("$containerOsVersion".StartsWith('10.0.18362.')) {
$containerOs = "1903"
}
elseif ("$containerOsVersion".StartsWith('10.0.18363.')) {
$containerOs = "1909"
}
elseif ("$containerOsVersion".StartsWith('10.0.19041.')) {
$containerOs = "2004"
}
elseif ("$containerOsVersion".StartsWith('10.0.19042.')) {
$containerOs = "20H2"
}
elseif ("$containerOsVersion".StartsWith('10.0.19043.')) {
$containerOs = "21H1"
}
elseif ("$containerOsVersion".StartsWith('10.0.19044.')) {
$containerOs = "21H2"
}
elseif ("$containerOsVersion".StartsWith('10.0.19045.')) {
$containerOs = "22H2"
}
elseif ("$containerOsVersion".StartsWith('10.0.20348.')) {
$containerOs = "ltsc2022"
}
else {
$containerOs = "unknown"
}

$containerOs = GetContainerOs -containerOsVersion $containerOsVersion

Write-Host "Generic Container OS Version: $containerOsVersion ($containerOs)"

$genericTagVersion = [Version]"$($inspect.Config.Labels.tag)"
Write-Host "Generic Tag of better generic: $genericTagVersion"
}

if ($hostOsVersion -eq $containerOsVersion) {
if ($isolation -eq "") {
$isolation = "process"
}
}
elseif ($hostOsVersion.Build -ge 20348 -and $containerOsVersion.Build -ge 20348) {
if ($isolation -eq "") {
Write-Host -ForegroundColor Yellow "WARNING: Container and host OS build is 20348 or above, defaulting to process isolation. If you encounter issues, you could try to install HyperV."
$isolation = "process"
}
}
elseif (("$hostOsVersion".StartsWith('10.0.19043.') -or "$hostOsVersion".StartsWith('10.0.19044.') -or "$hostOsVersion".StartsWith('10.0.19045.')) -and "$containerOsVersion".StartsWith("10.0.19041.")) {
if ($isolation -eq "") {
Write-Host -ForegroundColor Yellow "WARNING: Host OS is Windows 10 21H1 or newer and Container OS is 2004, defaulting to process isolation. If you experience problems, add -isolation hyperv."
$isolation = "process"
}
}
else {
if ($isolation -eq "") {
if ($isAdministrator) {
if (Get-HypervState -ne "Disabled") {
$isolation = "hyperv"
}
else {
$isolation = "process"
Write-Host -ForegroundColor Yellow "WARNING: Host OS and Base Image Container OS doesn't match and HyperV is not installed. If you encounter issues, you could try to install HyperV."
}
}
else {
$isolation = "hyperv"
Write-Host -ForegroundColor Yellow "WARNING: Host OS and Base Image Container OS doesn't match, defaulting to hyperv. If you do not have HyperV installed or you encounter issues, you could try to specify -isolation process"
}

}
elseif ($isolation -eq "process") {
Write-Host -ForegroundColor Yellow "WARNING: Host OS and Base Image Container OS doesn't match and process isolation is specified. If you encounter issues, you could try to specify -isolation hyperv"
}
}
$isolation = GetIsolationMode -hostOsVersion $hostOsVersion -containerOsVersion $containerOsVersion -useSSL $useSSL -isolation $isolation
Write-Host "Using $isolation isolation"

if ($isolation -eq "process" -and !$isServerHost -and ($os.BuildNumber -eq 22621 -or $os.BuildNumber -eq 22631 -or $os.BuildNumber -eq 26100) -and $useSSL) {
Expand Down
84 changes: 3 additions & 81 deletions ContainerHandling/New-NavImage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -355,48 +355,7 @@ try {
}

$containerOsVersion = [Version](Get-BcContainerOsVersion -containerOrImageName $baseImage)
if ("$containerOsVersion".StartsWith('10.0.14393.')) {
$containerOs = "ltsc2016"
}
elseif ("$containerOsVersion".StartsWith('10.0.15063.')) {
$containerOs = "1703"
}
elseif ("$containerOsVersion".StartsWith('10.0.16299.')) {
$containerOs = "1709"
}
elseif ("$containerOsVersion".StartsWith('10.0.17134.')) {
$containerOs = "1803"
}
elseif ("$containerOsVersion".StartsWith('10.0.17763.')) {
$containerOs = "ltsc2019"
}
elseif ("$containerOsVersion".StartsWith('10.0.18362.')) {
$containerOs = "1903"
}
elseif ("$containerOsVersion".StartsWith('10.0.18363.')) {
$containerOs = "1909"
}
elseif ("$containerOsVersion".StartsWith('10.0.19041.')) {
$containerOs = "2004"
}
elseif ("$containerOsVersion".StartsWith('10.0.19042.')) {
$containerOs = "20H2"
}
elseif ("$containerOsVersion".StartsWith('10.0.19043.')) {
$containerOs = "21H1"
}
elseif ("$containerOsVersion".StartsWith('10.0.19044.')) {
$containerOs = "21H2"
}
elseif ("$containerOsVersion".StartsWith('10.0.19045.')) {
$containerOs = "22H2"
}
elseif ("$containerOsVersion".StartsWith('10.0.20348.')) {
$containerOs = "ltsc2022"
}
else {
$containerOs = "unknown"
}
$containerOs = GetContainerOs -containerOsVersion $containerOsVersion
Write-Host "Container OS Version: $containerOsVersion ($containerOs)"
Write-Host "Host OS Version: $hostOsVersion ($hostOs)"

Expand All @@ -406,45 +365,8 @@ try {

throw "The container operating system is newer than the host operating system, cannot use image"
}

if ($hostOsVersion -eq $containerOsVersion) {
if ($isolation -eq "") {
$isolation = "process"
}
}
elseif ($hostOsVersion.Build -ge 20348 -and $containerOsVersion.Build -ge 20348) {
if ($isolation -eq "") {
Write-Host -ForegroundColor Yellow "WARNING: Container and host OS build is 20348 or above, defaulting to process isolation. If you encounter issues, you could try to install HyperV."
$isolation = "process"
}
}
elseif (("$hostOsVersion".StartsWith('10.0.19043.') -or "$hostOsVersion".StartsWith('10.0.19044.') -or "$hostOsVersion".StartsWith('10.0.19045.')) -and "$containerOsVersion".StartsWith("10.0.19041.")) {
if ($isolation -eq "") {
Write-Host -ForegroundColor Yellow "WARNING: Host OS is Windows 10 21H1 or newer and Container OS is 2004, defaulting to process isolation. If you experience problems, add -isolation hyperv."
$isolation = "process"
}
}
else {
if ($isolation -eq "") {
if ($isAdministrator) {
if (Get-HypervState -ne "Disabled") {
$isolation = "hyperv"
}
else {
$isolation = "process"
Write-Host "WARNING: Host OS and Base Image Container OS doesn't match and Hyper-V is not installed. If you encounter issues, you could try to install Hyper-V."
}
}
else {
$isolation = "hyperv"
Write-Host "WARNING: Host OS and Base Image Container OS doesn't match, defaulting to hyperv. If you do not have Hyper-V installed or you encounter issues, you could try to specify -isolation process"
}

}
elseif ($isolation -eq "process") {
Write-Host "WARNING: Host OS and Base Image Container OS doesn't match and process isolation is specified. If you encounter issues, you could try to specify -isolation hyperv"
}
}

$isolation = GetIsolationMode -hostOsVersion $hostOsVersion -containerOsVersion $containerOsVersion -useSSL $false -isolation $isolation
Write-Host "Using $isolation isolation"
}

Expand Down
Loading

0 comments on commit 5d25208

Please sign in to comment.