From a71489d9b38bbe373f2d10f76966d33acddb0720 Mon Sep 17 00:00:00 2001 From: Freddy Kristiansen Date: Tue, 23 Apr 2024 08:20:52 +0200 Subject: [PATCH] remove usepwsh false and require 1.0.2.20 (#3497) 1.0.2.20 now has SqlServer PS module preinstalled on PS 7 + compatible overrides --------- Co-authored-by: freddydk --- AppHandling/Clean-BcContainerDatabase.ps1 | 4 +-- AppHandling/Compile-AppInNavContainer.ps1 | 2 +- Bacpac/Backup-NavContainerDatabases.ps1 | 2 +- .../Export-NavContainerDatabasesAsBacpac.ps1 | 2 +- Bacpac/Restore-DatabasesInNavContainer.ps1 | 2 +- ContainerHandling/New-NavContainer.ps1 | 6 ++--- HelperFunctions.ps1 | 25 +++++++++---------- Misc/Set-BcContainerFeatureKeys.ps1 | 2 +- TenantHandling/New-NavContainerTenant.ps1 | 2 +- UserHandling/New-NavContainerNavUser.ps1 | 2 +- 10 files changed, 24 insertions(+), 25 deletions(-) diff --git a/AppHandling/Clean-BcContainerDatabase.ps1 b/AppHandling/Clean-BcContainerDatabase.ps1 index a7a593405..2211fee48 100644 --- a/AppHandling/Clean-BcContainerDatabase.ps1 +++ b/AppHandling/Clean-BcContainerDatabase.ps1 @@ -96,7 +96,7 @@ try { $copyTables += @("Entitlement", "Entitlement Set", "Membership Entitlement") } - Invoke-ScriptInBCContainer -containerName $containerName -usePwsh:$false -scriptblock { Param($platformVersion, $databaseName, $databaseServer, $databaseInstance, $copyTables, $multitenant) + Invoke-ScriptInBCContainer -containerName $containerName -scriptblock { Param($platformVersion, $databaseName, $databaseServer, $databaseInstance, $copyTables, $multitenant) Write-Host "Stopping ServiceTier in order to replace database" Set-NavServerInstance -ServerInstance $ServerInstance -stop @@ -196,7 +196,7 @@ try { if ($customconfig.Multitenant -eq "True") { Write-Host "Switching to multitenancy" - Invoke-ScriptInBCContainer -containerName $containerName -usePwsh:$false -scriptblock { Param($databaseName, $databaseServer, $databaseInstance) + Invoke-ScriptInBCContainer -containerName $containerName -scriptblock { Param($databaseName, $databaseServer, $databaseInstance) $databaseServerInstance = $databaseServer if ($databaseInstance) { $databaseServerInstance += "\$databaseInstance" diff --git a/AppHandling/Compile-AppInNavContainer.ps1 b/AppHandling/Compile-AppInNavContainer.ps1 index a2742c7e1..c2de295f4 100644 --- a/AppHandling/Compile-AppInNavContainer.ps1 +++ b/AppHandling/Compile-AppInNavContainer.ps1 @@ -367,7 +367,7 @@ try { # locate application version number in database if using SQLEXPRESS try { if (($customConfig.DatabaseServer -eq "localhost") -and ($customConfig.DatabaseInstance -eq "SQLEXPRESS")) { - $appVersion = Invoke-ScriptInBcContainer -containerName $containerName -usePwsh:$false -scriptblock { Param($databaseName) + $appVersion = Invoke-ScriptInBcContainer -containerName $containerName -scriptblock { Param($databaseName) (invoke-sqlcmd -ServerInstance 'localhost\SQLEXPRESS' -ErrorAction Stop -Query "SELECT [applicationversion] FROM [$databaseName].[dbo].[`$ndo`$dbproperty]").applicationVersion } -argumentList $customConfig.DatabaseName $publishedApps += @{ "Name" = "Application"; "Publisher" = "Microsoft"; "Version" = $appversion } diff --git a/Bacpac/Backup-NavContainerDatabases.ps1 b/Bacpac/Backup-NavContainerDatabases.ps1 index fece5b090..922a83e8f 100644 --- a/Bacpac/Backup-NavContainerDatabases.ps1 +++ b/Bacpac/Backup-NavContainerDatabases.ps1 @@ -49,7 +49,7 @@ try { } $containerBakFolder = Get-BcContainerPath -containerName $containerName -path $bakFolder -throw - Invoke-ScriptInBcContainer -containerName $containerName -usePwsh:$false -ScriptBlock { Param($containerBakfolder, $bakFolder, $tenant, $databasecredential, $compress) + Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock { Param($containerBakfolder, $bakFolder, $tenant, $databasecredential, $compress) function Backup { Param ( diff --git a/Bacpac/Export-NavContainerDatabasesAsBacpac.ps1 b/Bacpac/Export-NavContainerDatabasesAsBacpac.ps1 index d71f3d9ce..65e99c495 100644 --- a/Bacpac/Export-NavContainerDatabasesAsBacpac.ps1 +++ b/Bacpac/Export-NavContainerDatabasesAsBacpac.ps1 @@ -64,7 +64,7 @@ try { } $containerBacpacFolder = Get-BcContainerPath -containerName $containerName -path $bacpacFolder -throw - Invoke-ScriptInBcContainer -containerName $containerName -usePwsh:$false -ScriptBlock { Param([PSCredential]$sqlCredential, $bacpacFolder, $tenant, $commandTimeout, $includeDacPac, $diagnostics, $additionalArguments, $doNotCheckEntitlements) + Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock { Param([PSCredential]$sqlCredential, $bacpacFolder, $tenant, $commandTimeout, $includeDacPac, $diagnostics, $additionalArguments, $doNotCheckEntitlements) function CmdDo { Param( diff --git a/Bacpac/Restore-DatabasesInNavContainer.ps1 b/Bacpac/Restore-DatabasesInNavContainer.ps1 index ad384ded3..5fd766087 100644 --- a/Bacpac/Restore-DatabasesInNavContainer.ps1 +++ b/Bacpac/Restore-DatabasesInNavContainer.ps1 @@ -70,7 +70,7 @@ try { $containerBakFolder = Get-BcContainerPath -containerName $containerName -path $bakFolder -throw } - Invoke-ScriptInBCContainer -containerName $containerName -usePwsh:$false -scriptblock { Param($bakFolder, $bakFile, $databaseName, $tenant, $databaseFolder, $sqlTimeout) + Invoke-ScriptInBCContainer -containerName $containerName -scriptblock { Param($bakFolder, $bakFile, $databaseName, $tenant, $databaseFolder, $sqlTimeout) function Restore { Param ( diff --git a/ContainerHandling/New-NavContainer.ps1 b/ContainerHandling/New-NavContainer.ps1 index 4f833613a..d9864df61 100644 --- a/ContainerHandling/New-NavContainer.ps1 +++ b/ContainerHandling/New-NavContainer.ps1 @@ -779,7 +779,7 @@ try { $imageName = $bestImageName if ($artifactUrl) { $genericTagVersion = [Version](Get-BcContainerGenericTag -containerOrImageName $imageName) - if ($genericTagVersion -lt [Version]"1.0.2.15") { + if ($genericTagVersion -lt [Version]"1.0.2.20") { Write-Host "Generic image is version $genericTagVersion - pulling a newer image" $pullit = $true } @@ -2045,7 +2045,7 @@ if (-not `$restartingInstance) { if ($SqlServerMemoryLimit -and $customConfig.databaseServer -eq "localhost" -and $customConfig.databaseInstance -eq "SQLEXPRESS") { Write-Host "Set SQL Server memory limit to $SqlServerMemoryLimit MB" - Invoke-ScriptInBCContainer -containerName $containerName -usePwsh:$false -scriptblock { Param($SqlServerMemoryLimit) + Invoke-ScriptInBCContainer -containerName $containerName -scriptblock { Param($SqlServerMemoryLimit) Invoke-Sqlcmd -ServerInstance 'localhost\SQLEXPRESS' -Query "USE master EXEC sp_configure 'show advanced options', 1 RECONFIGURE WITH OVERRIDE;" Invoke-Sqlcmd -ServerInstance 'localhost\SQLEXPRESS' -Query "USE master EXEC sp_configure 'max server memory', $SqlServerMemoryLimit RECONFIGURE WITH OVERRIDE;" Invoke-Sqlcmd -ServerInstance 'localhost\SQLEXPRESS' -Query "USE master EXEC sp_configure 'show advanced options', 0 RECONFIGURE WITH OVERRIDE;" @@ -2443,7 +2443,7 @@ if (-not `$restartingInstance) { if ($multitenant) { Write-Host "Switching to multitenant" - Invoke-ScriptInBCContainer -containerName $containerName -usePwsh:$false -scriptblock { + Invoke-ScriptInBCContainer -containerName $containerName -scriptblock { $customConfigFile = Join-Path (Get-Item "C:\Program Files\Microsoft Dynamics NAV\*\Service").FullName "CustomSettings.config" [xml]$customConfig = [System.IO.File]::ReadAllText($customConfigFile) diff --git a/HelperFunctions.ps1 b/HelperFunctions.ps1 index fdd4f197c..bcaeb33fc 100644 --- a/HelperFunctions.ps1 +++ b/HelperFunctions.ps1 @@ -1259,6 +1259,17 @@ function DownloadLatestAlLanguageExtension { [switch] $allowPrerelease ) + # Check if we already have the latest version downloaded and located in this session + if ($script:AlLanguageExtenssionPath[$allowPrerelease.IsPresent]) { + $path = $script:AlLanguageExtenssionPath[$allowPrerelease.IsPresent] + if (Test-Path $path -PathType Container) { + return $path + } + else { + $script:AlLanguageExtenssionPath[$allowPrerelease.IsPresent] = '' + } + } + $mutexName = "DownloadAlLanguageExtension" $mutex = New-Object System.Threading.Mutex($false, $mutexName) try { @@ -1273,17 +1284,6 @@ function DownloadLatestAlLanguageExtension { Write-Host "Other process terminated abnormally" } - # Check if we already have the latest version downloaded and located in this session - if ($script:AlLanguageExtenssionPath[$allowPrerelease.IsPresent]) { - $path = $script:AlLanguageExtenssionPath[$allowPrerelease.IsPresent] - if (Test-Path $path -PathType Container) { - return $path - } - else { - $script:AlLanguageExtenssionPath[$allowPrerelease.IsPresent] = '' - } - } - $version, $url = GetLatestAlLanguageExtensionVersionAndUrl -allowPrerelease:$allowPrerelease $path = Join-Path $bcContainerHelperConfig.hostHelperFolder "alLanguageExtension/$version" if (!(Test-Path $path -PathType Container)) { @@ -1312,8 +1312,7 @@ function RunAlTool { Param( [string[]] $arguments ) - # ALTOOL is at the moment only available in prerelease - $path = DownloadLatestAlLanguageExtension -allowPrerelease + $path = DownloadLatestAlLanguageExtension if ($isLinux) { $alToolExe = Join-Path $path 'extension/bin/linux/altool' Write-Host "Setting execute permissions on altool" diff --git a/Misc/Set-BcContainerFeatureKeys.ps1 b/Misc/Set-BcContainerFeatureKeys.ps1 index 39f6d35d8..6c2e27c2f 100644 --- a/Misc/Set-BcContainerFeatureKeys.ps1 +++ b/Misc/Set-BcContainerFeatureKeys.ps1 @@ -26,7 +26,7 @@ $telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -paramet try { if ($featureKeys.Keys.Count -ne 0) { - Invoke-ScriptInBCContainer -containerName $containerName -usePwsh:$false -ScriptBlock { Param([string] $tenant, [hashtable] $featureKeys) + Invoke-ScriptInBCContainer -containerName $containerName -ScriptBlock { Param([string] $tenant, [hashtable] $featureKeys) $customConfigFile = Join-Path (Get-Item "C:\Program Files\Microsoft Dynamics NAV\*\Service").FullName "CustomSettings.config" [xml]$customConfig = [System.IO.File]::ReadAllText($customConfigFile) $databaseServer = $customConfig.SelectSingleNode("//appSettings/add[@key='DatabaseServer']").Value diff --git a/TenantHandling/New-NavContainerTenant.ps1 b/TenantHandling/New-NavContainerTenant.ps1 index ea3649f25..bc9dd9175 100644 --- a/TenantHandling/New-NavContainerTenant.ps1 +++ b/TenantHandling/New-NavContainerTenant.ps1 @@ -46,7 +46,7 @@ try { throw "You cannot add a tenant called tenant" } - Invoke-ScriptInBcContainer -containerName $containerName -usePwsh:$false -ScriptBlock { Param($containerName, $tenantId, [PSCredential]$sqlCredential, $sourceDatabase, $destinationDatabase, $alternateId, $doNotCopyDatabase, $allowAppDatabaseWrite, $applicationInsightsKey) + Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock { Param($containerName, $tenantId, [PSCredential]$sqlCredential, $sourceDatabase, $destinationDatabase, $alternateId, $doNotCopyDatabase, $allowAppDatabaseWrite, $applicationInsightsKey) $customConfigFile = Join-Path (Get-Item "C:\Program Files\Microsoft Dynamics NAV\*\Service").FullName "CustomSettings.config" [xml]$customConfig = [System.IO.File]::ReadAllText($customConfigFile) diff --git a/UserHandling/New-NavContainerNavUser.ps1 b/UserHandling/New-NavContainerNavUser.ps1 index e66ba8b58..92c6b6ed8 100644 --- a/UserHandling/New-NavContainerNavUser.ps1 +++ b/UserHandling/New-NavContainerNavUser.ps1 @@ -57,7 +57,7 @@ $telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -paramet try { $navversion = Get-BcContainerNavversion -containerOrImageName $containerName $version = [System.Version]($navversion.split('-')[0]) - Invoke-ScriptInBcContainer -containerName $containerName -usePwsh:$false -ScriptBlock { param([PSCredential]$Credential, [string]$Tenant, [string]$WindowsAccount, [string]$AuthenticationEMail, [bool]$ChangePasswordAtNextLogOn, [string]$PermissionSetId, [string]$AppName, [string]$AppPublisher, $assignPremiumPlan, [PSCredential]$databaseCredential, [string]$fullName, [System.Version]$version) + Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock { param([PSCredential]$Credential, [string]$Tenant, [string]$WindowsAccount, [string]$AuthenticationEMail, [bool]$ChangePasswordAtNextLogOn, [string]$PermissionSetId, [string]$AppName, [string]$AppPublisher, $assignPremiumPlan, [PSCredential]$databaseCredential, [string]$fullName, [System.Version]$version) $TenantParam = @{} if ($Tenant) {