From 118144c1237c7a982d695130ab13705c4b31a68d Mon Sep 17 00:00:00 2001 From: Oliver Hahn Date: Fri, 28 Aug 2026 10:15:39 +0200 Subject: [PATCH] Bugfix 2026-08-28 --- .../labautomation/deploy-lab.ps1 | 12 +-- .../labautomation/scripts/Configure-SQLMI.ps1 | 3 +- .../scripts/Configure-TeamWallpaper.ps1 | 2 + .../scripts/Configure-legacySQL-DB.ps1 | 44 +++++------ .../scripts/Configure-legacySQL.ps1 | 20 ++--- .../scripts/Restore-TeamDatabases.ps1 | 78 ------------------- .../labautomation/shared-deploy-lab.ps1 | 25 +++--- 7 files changed, 48 insertions(+), 136 deletions(-) diff --git a/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/deploy-lab.ps1 b/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/deploy-lab.ps1 index a4f992441..29cae4e30 100644 --- a/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/deploy-lab.ps1 +++ b/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/deploy-lab.ps1 @@ -88,8 +88,13 @@ $vmPostfix = $vmPostfix -replace "_", "-" $vmName = "VM-$vmPostfix" $TeamName = $me.ShortName $TeamName = $TeamName.ToUpper() -$legacySQLName = "legacySQL2016" +# feed the effective resource group back to the console +@{"HackboxCredential" = @{ name = "ResourceGroupName" ; value = $effectiveResourceGroup; note = "The name of the resource group where lab resources are deployed" }} +@{"HackboxCredential" = @{ name = "Team VM Name" ; value = $vmName; note = "The name of the Team VM" }} +@{"HackboxCredential" = @{ name = "Team / Link Name" ; value = $TeamName; note = "Name of the Team (Prefix for DBs and to use as Link Name for SQLMI)" }} + +$legacySQLName = "legacySQL2016" $storageAccountName = Get-AzStorageAccount -ResourceGroupName $sharedResourceGroupName -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty StorageAccountName $managedInstanceFQDN = Get-AzSqlInstance -ResourceGroupName $sharedResourceGroupName -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullyQualifiedDomainName @@ -121,8 +126,3 @@ Write-Host "[$SubscriptionId] Lab deployment completed successfully" Write-Host "[$SubscriptionId] Lab Resource Group: $effectiveResourceGroup" Write-Host "[$SubscriptionId] Shared Resource Group: $sharedResourceGroupName" Write-Host "[$SubscriptionId] Result: $($result)" - -# feed the effective resource group back to the console -@{"HackboxCredential" = @{ name = "ResourceGroupName" ; value = $effectiveResourceGroup; note = "The name of the resource group where lab resources are deployed" }} -@{"HackboxCredential" = @{ name = "Team VM Name" ; value = $vmName; note = "The name of the Team VM" }} -@{"HackboxCredential" = @{ name = "Team / Link Name" ; value = $TeamName; note = "Name of the Team (Prefix for DBs and to use as Link Name for SQLMI)" }} diff --git a/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/scripts/Configure-SQLMI.ps1 b/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/scripts/Configure-SQLMI.ps1 index 615564e65..23bf656cb 100644 --- a/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/scripts/Configure-SQLMI.ps1 +++ b/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/scripts/Configure-SQLMI.ps1 @@ -499,7 +499,8 @@ try { #Write-Host "Skript erfolgreich auf SQL MI ausgeführt." -ForegroundColor Green } catch { - Write-Error "Fehler bei der Ausführung: $_" + $ErrorString = $_ | format-list -force | Out-String + Write-Error "ERR: $ErrorString" } finally { if ($null -ne $serverConnection -and $serverConnection.IsOpen) { diff --git a/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/scripts/Configure-TeamWallpaper.ps1 b/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/scripts/Configure-TeamWallpaper.ps1 index 9595cb30e..0c2fd362d 100644 --- a/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/scripts/Configure-TeamWallpaper.ps1 +++ b/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/scripts/Configure-TeamWallpaper.ps1 @@ -79,6 +79,8 @@ try { } catch { Write-Host "An error occurred while configuring the team wallpaper: $_" + $ErrorString = $_ | format-list -force | Out-String + Write-Error "ERR: $ErrorString" } Stop-Transcript \ No newline at end of file diff --git a/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/scripts/Configure-legacySQL-DB.ps1 b/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/scripts/Configure-legacySQL-DB.ps1 index b5c73b668..b2b8f5d55 100644 --- a/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/scripts/Configure-legacySQL-DB.ps1 +++ b/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/scripts/Configure-legacySQL-DB.ps1 @@ -26,29 +26,20 @@ WHERE DECLARE @DBName VARCHAR(255) DECLARE @SQLCmd NVARCHAR(MAX) -DECLARE DB_Crs CURSOR READ_ONLY FORWARD_ONLY FOR SELECT name FROM sys.databases WHERE name = '$($TeamName)_TenantDataDB' AND state_desc = 'ONLINE' -OPEN DB_Crs -FETCH NEXT FROM DB_Crs INTO @DBName +SET @DBName = '$($TeamName)_TenantDataDB' -WHILE @@FETCH_STATUS = 0 -BEGIN - SET @SQLCmd = 'USE [' + @DBName + '] - ALTER ASSEMBLY CLRUFDS WITH PERMISSION_SET = UNSAFE; - ALTER ASSEMBLY Database1 WITH PERMISSION_SET = UNSAFE; - ' - --PRINT @SQLCmd - EXEC (@SQLCmd) +SET @SQLCmd = 'USE [' + @DBName + ']; +ALTER ASSEMBLY CLRUFDS WITH PERMISSION_SET = UNSAFE; +ALTER ASSEMBLY Database1 WITH PERMISSION_SET = UNSAFE; +' +--PRINT @SQLCmd +EXEC (@SQLCmd) - SET @SQLCmd = 'ALTER DATABASE [' + @DBName + '] - ADD LOG FILE (NAME = N''' + @DBName + '_Log2'', FILENAME = N''' + @DefaultLogPath + @DBName + '_Log2.ldf''); - ' - --PRINT @SQLCmd - EXEC (@SQLCmd) - - FETCH NEXT FROM DB_Crs INTO @DBName -END -CLOSE DB_Crs -DEALLOCATE DB_Crs +SET @SQLCmd = 'ALTER DATABASE [' + @DBName + '] +ADD LOG FILE (NAME = N''' + @DBName + '_Log2'', FILENAME = N''' + @DefaultLogPath + @DBName + '_Log2.ldf''); +' +--PRINT @SQLCmd +EXEC (@SQLCmd) "@ $connectionString = "Data Source=$ServerInstance;Initial Catalog=master;TrustServerCertificate=True;" @@ -66,12 +57,15 @@ try { $command.CommandTimeout = $QueryTimeout $command.CommandText = $ConfigureSql - $result = $command.ExecuteReader() - $table = New-Object System.Data.DataTable - $table.Load($result) + $result = $command.ExecuteNonQuery() + #$result = $command.ExecuteReader() + #$table = New-Object System.Data.DataTable + #$table.Load($result) } catch { - Write-Error "Fehler bei der Ausführung: $_" + Write-Host $result + $ErrorString = $_ | format-list -force | Out-String + Write-Error "ERR: $ErrorString" } finally { if ($null -ne $serverConnection -and $serverConnection.IsOpen) { diff --git a/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/scripts/Configure-legacySQL.ps1 b/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/scripts/Configure-legacySQL.ps1 index b4cccbbde..1938175a6 100644 --- a/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/scripts/Configure-legacySQL.ps1 +++ b/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/scripts/Configure-legacySQL.ps1 @@ -34,18 +34,7 @@ $Connection = New-Object System.Data.SqlClient.SqlConnection($connectionString) $SQLPwd.MakeReadOnly() $cred = New-Object System.Data.SqlClient.SqlCredential($sqlusername,$SQLPwd) $Connection.credential = $cred -#$Connection.open() -#$command = New-Object system.Data.SqlClient.SqlCommand($Connection) -#$command.Connection = $Connection -#$command.CommandTimeout = $QueryTimeout - -#$command.CommandText = $ConfigureSql -#$result = $command.ExecuteReader() -#$table = New-Object System.Data.DataTable -#$table.Load($result) - -# 5. SMO-Serververbindung initialisieren $serverConnection = New-Object Microsoft.SqlServer.Management.Common.ServerConnection($Connection) $server = New-Object Microsoft.SqlServer.Management.Smo.Server($serverConnection) @@ -55,7 +44,8 @@ try { #Write-Host "Skript erfolgreich auf SQL MI ausgeführt." -ForegroundColor Green } catch { - Write-Error "Fehler bei der Ausführung: $_" + $ErrorString = $_ | format-list -force | Out-String + Write-Error "ERR: $ErrorString" } finally { if ($null -ne $serverConnection -and $serverConnection.IsOpen) { @@ -72,11 +62,13 @@ Try { Write-Host "Installing and configuring Windows Failover Cluster..." -ForegroundColor Green Install-WindowsFeature -Name Failover-Clustering -IncludeManagementTools -IncludeAllSubFeature $clus = New-Cluster -Name "CLU01" -AdministrativeAccessPoint None -Verbose -Force - Enable-SqlAlwaysOn -Path SQLSERVER:\SQL\legacysql2016\default -Force + Enable-SqlAlwaysOn -Path "SQLSERVER:\SQL\$($ServerInstance)\default" -Force Restart-Service -Name "MSSQLSERVER" -Force } Catch { - Write-Host "Error configuring SQL legacy Instance: $_" + Write-Host "Error configuring SQL legacy Instance." + $ErrorString = $_ | format-list -force | Out-String + Write-Error "ERR: $ErrorString" } Stop-Transcript diff --git a/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/scripts/Restore-TeamDatabases.ps1 b/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/scripts/Restore-TeamDatabases.ps1 index 569e8bf5e..90a4403d8 100644 --- a/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/scripts/Restore-TeamDatabases.ps1 +++ b/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/scripts/Restore-TeamDatabases.ps1 @@ -585,15 +585,6 @@ END; # Main # --------------------------------------------------------------------------- -if (-not (Test-Path -LiteralPath $DownloadDirectory)) -{ - New-Item ` - -ItemType Directory ` - -Path $DownloadDirectory ` - -Force | - Out-Null -} - Write-Host "Testing SQL Server connection to [$ServerInstance]..." $serverInformation = Invoke-DatabaseQuery -Query @" @@ -621,75 +612,6 @@ foreach ($backupName in $backupNames) { $fileName = "$backupName.bak" $destination = Join-Path $DownloadDirectory $fileName - $downloadUri = Get-BackupDownloadUri ` - -BaseUri $BackupBaseUri ` - -FileName $fileName - - if ((Test-Path -LiteralPath $destination) -and - -not $ForceDownload.IsPresent) - { - Write-Host "Using existing backup: $destination" - } - else - { - Write-Host "Downloading [$fileName] from $downloadUri ..." - - $temporaryFile = "$destination.download" - - Remove-Item ` - -LiteralPath $temporaryFile ` - -Force ` - -ErrorAction SilentlyContinue - - try - { - $invokeWebRequestParameters = @{ - Uri = $downloadUri - OutFile = $temporaryFile - ErrorAction = "Stop" - } - - # UseBasicParsing exists in Windows PowerShell 5.1 but not in - # newer editions in the same form. - if ($PSVersionTable.PSEdition -eq "Desktop") - { - $invokeWebRequestParameters.UseBasicParsing = $true - } - - $lastProgressPreference = $ProgressPreference - $ProgressPreference = 'SilentlyContinue' - Invoke-WebRequest @invokeWebRequestParameters - $ProgressPreference = $lastProgressPreference - - if (-not (Test-Path -LiteralPath $temporaryFile)) - { - throw "The downloaded file was not created." - } - - if ((Get-Item -LiteralPath $temporaryFile).Length -eq 0) - { - throw "The downloaded file is empty." - } - - Move-Item ` - -LiteralPath $temporaryFile ` - -Destination $destination ` - -Force - } - catch - { - Remove-Item ` - -LiteralPath $temporaryFile ` - -Force ` - -ErrorAction SilentlyContinue - - throw "Download of [$fileName] failed: $($_.Exception.Message)" - } - - Write-Host "Downloaded [$fileName] to [$destination]." ` - -ForegroundColor Green - } - $downloadedBackups[$backupName] = $destination } diff --git a/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/shared-deploy-lab.ps1 b/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/shared-deploy-lab.ps1 index 17bb4e933..a59ad516c 100644 --- a/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/shared-deploy-lab.ps1 +++ b/03-Azure/01-02 Data/02-SQL_Modernization/labautomation/shared-deploy-lab.ps1 @@ -110,6 +110,16 @@ Write-Host "[$SubscriptionId] Result: $($result)" $managedInstance = Get-AzSqlInstance -ResourceGroupName $sharedResourceGroup -ErrorAction SilentlyContinue | Select-Object -First 1 $managedInstanceName = $managedInstance.ManagedInstanceName $managedInstanceFQDN = $managedInstance.FullyQualifiedDomainName + +@{"HackboxCredential" = @{name = 'Legacy SQL Server Name'; value = $legacySQLName; note = 'Name of legacy SQL Server'}} +@{"HackboxCredential" = @{name = 'SQLMI FQDN'; value = $managedInstanceFQDN; note = 'FQDN of SQLMI'}} +@{"HackboxCredential" = @{name = 'Arc SQL Server Name'; value = $arcSQLName; note = 'Name of new SQL Server'}} + +@{"HackboxCredential" = @{name = 'VM User Name'; value = $adminUsername; note = 'Username to connect for every VM'}} +@{"HackboxCredential" = @{name = 'VM User Password'; value = $adminPassword; note = 'Password to connect to every VM'}} +@{"HackboxCredential" = @{name = 'SQLMI User Name'; value = $sqlMiAdminUsername; note = 'Username to connect to SQLMI'}} +@{"HackboxCredential" = @{name = 'SQLMI User Password'; value = $sqlMiAdminPassword; note = 'Password to connect to SQLMI'}} + [string]$managedInstanceResourceId = $managedInstance.Id #$managedInstancePrincipalId = $managedInstance.Identity.PrincipalId @@ -123,9 +133,9 @@ try { } catch { Write-Host "Failed to grant 'Directory Readers' to Managed Identity of $managedInstanceFQDN." -ForegroundColor Red - $ErrorString = $_ | format-list -force | Out-String - Write-Host "ERR: $ErrorString" -ForegroundColor Red Write-Host $return + $ErrorString = $_ | format-list -force | Out-String + Write-Error "ERR: $ErrorString" } Start-Sleep -Seconds 30 @@ -160,7 +170,7 @@ try { catch { Write-Host "Failed to set Entra ID Admin on $managedInstanceFQDN." -ForegroundColor Red $ErrorString = $_ | format-list -force | Out-String - Write-Host "ERR: $ErrorString" -ForegroundColor Red + Write-Error "ERR: $ErrorString" } $timeoutSeconds = 120 @@ -194,12 +204,3 @@ if (-not $found) { throw "Expected Entra ID Admin was not configured within 2 minutes." } - -@{"HackboxCredential" = @{name = 'Legacy SQL Server Name'; value = $legacySQLName; note = 'Name of legacy SQL Server'}} -@{"HackboxCredential" = @{name = 'SQLMI FQDN'; value = $managedInstanceFQDN; note = 'FQDN of SQLMI'}} -@{"HackboxCredential" = @{name = 'Arc SQL Server Name'; value = $arcSQLName; note = 'Name of new SQL Server'}} - -@{"HackboxCredential" = @{name = 'VM User Name'; value = $adminUsername; note = 'Username to connect for every VM'}} -@{"HackboxCredential" = @{name = 'VM User Password'; value = $adminPassword; note = 'Password to connect to every VM'}} -@{"HackboxCredential" = @{name = 'SQLMI User Name'; value = $sqlMiAdminUsername; note = 'Username to connect to SQLMI'}} -@{"HackboxCredential" = @{name = 'SQLMI User Password'; value = $sqlMiAdminPassword; note = 'Password to connect to SQLMI'}}