From 707030e6cb121462b17f7ab410491a7c4592159b Mon Sep 17 00:00:00 2001 From: Andreas Jordan Date: Mon, 10 Aug 2026 20:52:48 +0200 Subject: [PATCH] Progress bars - Complete the bars that 22 commands left behind These commands started a progress bar with Write-Progress or Write-ProgressHelper and never completed it, so the bar stayed on screen after the command returned. Each one now completes its bar, using the pattern the rest of the module already uses. Commands that run a sequential and a parallel branch complete both, and the bars started with an explicit -Id are completed with that same Id. Remove-DbaNetworkCertificate also drops four -Target arguments passed to Write-ProgressHelper, which has no such parameter. The helper is a simple function, so the argument was silently landing in $args and doing nothing. (do Disable-DbaDbEncryption, Export-DbaUser, Find-DbaInstance, Import-DbaCsv, Import-DbaParquet, Install-DbaSqlWatch, Invoke-DbaDbDataGenerator, Invoke-DbaDbDataMasking, Invoke-DbaDbMirroring, New-DbaComputerCertificate, New-DbaComputerCertificateSigningRequest, New-DbatoolsSupportPackage, Read-DbaBackupHeader, Remove-DbaNetworkCertificate, Reset-DbaAdmin, Save-DbaDiagnosticQueryScript, Set-DbaNetworkCertificate, Start-DbaDbEncryption, Start-DbaMigration, Stop-DbaDbEncryption, Sync-DbaAvailabilityGroup, Sync-DbaLoginPermission) Co-Authored-By: Claude Opus 5 (1M context) --- public/Disable-DbaDbEncryption.ps1 | 1 + public/Export-DbaUser.ps1 | 1 + public/Find-DbaInstance.ps1 | 1 + public/Import-DbaCsv.ps1 | 1 + public/Import-DbaParquet.ps1 | 1 + public/Install-DbaSqlWatch.ps1 | 1 + public/Invoke-DbaDbDataGenerator.ps1 | 1 + public/Invoke-DbaDbDataMasking.ps1 | 1 + public/Invoke-DbaDbMirroring.ps1 | 1 + public/New-DbaComputerCertificate.ps1 | 1 + public/New-DbaComputerCertificateSigningRequest.ps1 | 1 + public/New-DbatoolsSupportPackage.ps1 | 2 ++ public/Read-DbaBackupHeader.ps1 | 1 + public/Remove-DbaNetworkCertificate.ps1 | 9 +++++---- public/Reset-DbaAdmin.ps1 | 1 + public/Save-DbaDiagnosticQueryScript.ps1 | 2 ++ public/Set-DbaNetworkCertificate.ps1 | 1 + public/Start-DbaDbEncryption.ps1 | 2 ++ public/Start-DbaMigration.ps1 | 1 + public/Stop-DbaDbEncryption.ps1 | 2 ++ public/Sync-DbaAvailabilityGroup.ps1 | 1 + public/Sync-DbaLoginPermission.ps1 | 1 + 22 files changed, 30 insertions(+), 4 deletions(-) diff --git a/public/Disable-DbaDbEncryption.ps1 b/public/Disable-DbaDbEncryption.ps1 index 6be767108731..81ea15a23255 100644 --- a/public/Disable-DbaDbEncryption.ps1 +++ b/public/Disable-DbaDbEncryption.ps1 @@ -126,6 +126,7 @@ function Disable-DbaDbEncryption { Write-Message -Level Verbose -Message "Database state for $($db.Name) on $($server.Name): $($db.DatabaseEncryptionKey.EncryptionState)" } while ($db.DatabaseEncryptionKey.EncryptionState -notin "Unencrypted", "None") + Write-ProgressHelper -Completed if (-not $NoEncryptionKeyDrop) { # https://www.sqlservercentral.com/steps/stairway-to-tde-removing-tde-from-a-database diff --git a/public/Export-DbaUser.ps1 b/public/Export-DbaUser.ps1 index 9ae28df9797b..de500bac7342 100644 --- a/public/Export-DbaUser.ps1 +++ b/public/Export-DbaUser.ps1 @@ -645,6 +645,7 @@ function Export-DbaUser { $sql } } + Write-ProgressHelper -Completed } # Just a single file, output path once here if (-Not $GenerateFilePerUser -and $FilePath) { diff --git a/public/Find-DbaInstance.ps1 b/public/Find-DbaInstance.ps1 index 13479860a1ee..c81648f929a2 100644 --- a/public/Find-DbaInstance.ps1 +++ b/public/Find-DbaInstance.ps1 @@ -597,6 +597,7 @@ function Find-DbaInstance { } } + Write-ProgressHelper -Activity "Processing: $($computer)" -Completed $masterList | Where-Object { $_.Confidence -ge $MinimumConfidence } } } diff --git a/public/Import-DbaCsv.ps1 b/public/Import-DbaCsv.ps1 index eb5da19bbc3c..a2420f97839e 100644 --- a/public/Import-DbaCsv.ps1 +++ b/public/Import-DbaCsv.ps1 @@ -1500,6 +1500,7 @@ WHERE c.object_id = OBJECT_ID(@tableName) } else { Write-Progress -Id 1 -Activity "Inserting $($script:totalRowsCopied) rows" -Status "Failed" -Completed } + Write-Progress -Activity "Importing from $file" -Completed } } if ($PSCmdlet.ShouldProcess($instance, "Finalizing import")) { diff --git a/public/Import-DbaParquet.ps1 b/public/Import-DbaParquet.ps1 index c32fa0cdf746..32efe47cbf24 100644 --- a/public/Import-DbaParquet.ps1 +++ b/public/Import-DbaParquet.ps1 @@ -1038,6 +1038,7 @@ WHERE c.object_id = OBJECT_ID(@tableName) } else { Write-Progress -Id 1 -Activity "Inserting $($script:totalRowsCopied) rows" -Status "Failed" -Completed } + Write-Progress -Activity "Importing from $file" -Completed } } # Clean up Parquet reader if ShouldProcess was skipped (WhatIf mode) diff --git a/public/Install-DbaSqlWatch.ps1 b/public/Install-DbaSqlWatch.ps1 index b0c2d7ab8223..51cc1b039cd5 100644 --- a/public/Install-DbaSqlWatch.ps1 +++ b/public/Install-DbaSqlWatch.ps1 @@ -196,5 +196,6 @@ function Install-DbaSqlWatch { Write-Message -Level Verbose -Message "Finished installing/updating SqlWatch in $database on $instance." } } + Write-ProgressHelper -Completed } } \ No newline at end of file diff --git a/public/Invoke-DbaDbDataGenerator.ps1 b/public/Invoke-DbaDbDataGenerator.ps1 index 4c7c2101e5c6..a084de372334 100644 --- a/public/Invoke-DbaDbDataGenerator.ps1 +++ b/public/Invoke-DbaDbDataGenerator.ps1 @@ -555,6 +555,7 @@ function Invoke-DbaDbDataGenerator { } } } + Write-ProgressHelper -Completed try { $sqlconn.Close() diff --git a/public/Invoke-DbaDbDataMasking.ps1 b/public/Invoke-DbaDbDataMasking.ps1 index 90685c9d09ee..4b36c82ec6a1 100644 --- a/public/Invoke-DbaDbDataMasking.ps1 +++ b/public/Invoke-DbaDbDataMasking.ps1 @@ -1374,6 +1374,7 @@ function Invoke-DbaDbDataMasking { } } } # End foreach database + Write-ProgressHelper -Completed # Do some cleanup $null = $server.Databases['tempdb'].Tables.Refresh() diff --git a/public/Invoke-DbaDbMirroring.ps1 b/public/Invoke-DbaDbMirroring.ps1 index 7863eb17014f..7da7af98c18f 100644 --- a/public/Invoke-DbaDbMirroring.ps1 +++ b/public/Invoke-DbaDbMirroring.ps1 @@ -426,5 +426,6 @@ function Invoke-DbaDbMirroring { } } } + Write-ProgressHelper -Completed } } \ No newline at end of file diff --git a/public/New-DbaComputerCertificate.ps1 b/public/New-DbaComputerCertificate.ps1 index 3d6d4ee79069..c2dce0af3547 100644 --- a/public/New-DbaComputerCertificate.ps1 +++ b/public/New-DbaComputerCertificate.ps1 @@ -526,6 +526,7 @@ function New-DbaComputerCertificate { Stop-Function "Isue removing files from $certDir" -Target $certDir -ErrorRecord $_ } } + Write-ProgressHelper -Completed } } } \ No newline at end of file diff --git a/public/New-DbaComputerCertificateSigningRequest.ps1 b/public/New-DbaComputerCertificateSigningRequest.ps1 index c9bc97a566b2..dba75966554c 100644 --- a/public/New-DbaComputerCertificateSigningRequest.ps1 +++ b/public/New-DbaComputerCertificateSigningRequest.ps1 @@ -258,6 +258,7 @@ function New-DbaComputerCertificateSigningRequest { } Get-ChildItem $certCfg, $certCsr } + Write-ProgressHelper -Completed } } } \ No newline at end of file diff --git a/public/New-DbatoolsSupportPackage.ps1 b/public/New-DbatoolsSupportPackage.ps1 index 26f8e207b6a3..7ea4d5cbc409 100644 --- a/public/New-DbatoolsSupportPackage.ps1 +++ b/public/New-DbatoolsSupportPackage.ps1 @@ -201,6 +201,8 @@ Ideally start a new console, perform the minimal steps required to reproduce the $hash["Variables"] = $Variables | Get-Variable -ErrorAction Ignore } + Write-ProgressHelper -Completed + $data = [PSCustomObject]$hash try { diff --git a/public/Read-DbaBackupHeader.ps1 b/public/Read-DbaBackupHeader.ps1 index 9091caa67af9..237e9225021b 100644 --- a/public/Read-DbaBackupHeader.ps1 +++ b/public/Read-DbaBackupHeader.ps1 @@ -374,6 +374,7 @@ function Read-DbaBackupHeader { } Start-Sleep -Milliseconds 500 } + Write-Progress -Id 1 -Activity Updating -Completed #Close the runspace pool $runspacePool.Close() [System.Management.Automation.Runspaces.Runspace]::DefaultRunspace = $defaultrunspace diff --git a/public/Remove-DbaNetworkCertificate.ps1 b/public/Remove-DbaNetworkCertificate.ps1 index 54167d00bb5f..616662fdfb81 100644 --- a/public/Remove-DbaNetworkCertificate.ps1 +++ b/public/Remove-DbaNetworkCertificate.ps1 @@ -116,10 +116,10 @@ function Remove-DbaNetworkCertificate { if ([System.String]::IsNullOrEmpty($vsname)) { $vsname = $instance } - Write-ProgressHelper -StepNumber ($stepCounter++) -Message "Regroot: $regRoot" -Target $instance - Write-ProgressHelper -StepNumber ($stepCounter++) -Message "ServiceAcct: $serviceAccount" -Target $instance - Write-ProgressHelper -StepNumber ($stepCounter++) -Message "InstanceName: $instanceName" -Target $instance - Write-ProgressHelper -StepNumber ($stepCounter++) -Message "VSNAME: $vsname" -Target $instance + Write-ProgressHelper -StepNumber ($stepCounter++) -Message "Regroot: $regRoot" + Write-ProgressHelper -StepNumber ($stepCounter++) -Message "ServiceAcct: $serviceAccount" + Write-ProgressHelper -StepNumber ($stepCounter++) -Message "InstanceName: $instanceName" + Write-ProgressHelper -StepNumber ($stepCounter++) -Message "VSNAME: $vsname" $scriptblock = { $regRoot = $args[0] @@ -147,6 +147,7 @@ function Remove-DbaNetworkCertificate { Stop-Function -Message "Failed to connect to $($resolved.fqdn) using PowerShell remoting." -ErrorRecord $_ -Target $instance -Continue } } + Write-ProgressHelper -Completed } } } \ No newline at end of file diff --git a/public/Reset-DbaAdmin.ps1 b/public/Reset-DbaAdmin.ps1 index d2fffc72e8ed..9a57c8c90929 100644 --- a/public/Reset-DbaAdmin.ps1 +++ b/public/Reset-DbaAdmin.ps1 @@ -448,6 +448,7 @@ function Reset-DbaAdmin { } } } + Write-ProgressHelper -Completed } } diff --git a/public/Save-DbaDiagnosticQueryScript.ps1 b/public/Save-DbaDiagnosticQueryScript.ps1 index bb0d53a56284..368b6f68678f 100644 --- a/public/Save-DbaDiagnosticQueryScript.ps1 +++ b/public/Save-DbaDiagnosticQueryScript.ps1 @@ -217,8 +217,10 @@ function Save-DbaDiagnosticQueryScript { Invoke-TlsWebRequest -Uri $link -OutFile $filename -ErrorAction Stop Get-ChildItem -Path $filename } catch { + Write-ProgressHelper -Completed Stop-Function -Message "Requesting and writing file failed: $_" -Target $filename -ErrorRecord $_ return } } + Write-ProgressHelper -Completed } \ No newline at end of file diff --git a/public/Set-DbaNetworkCertificate.ps1 b/public/Set-DbaNetworkCertificate.ps1 index 1f825e1f3b1b..755f76bbef92 100644 --- a/public/Set-DbaNetworkCertificate.ps1 +++ b/public/Set-DbaNetworkCertificate.ps1 @@ -404,6 +404,7 @@ function Set-DbaNetworkCertificate { Notes = $notes } } + Write-ProgressHelper -Completed } } } diff --git a/public/Start-DbaDbEncryption.ps1 b/public/Start-DbaDbEncryption.ps1 index 689ab20866e8..a974af83c699 100644 --- a/public/Start-DbaDbEncryption.ps1 +++ b/public/Start-DbaDbEncryption.ps1 @@ -383,6 +383,7 @@ function Start-DbaDbEncryption { Stop-Function -Message "Failure" -ErrorRecord $_ -Continue } } + Write-ProgressHelper -Completed } else { # Parallel processing - group databases by instance and pre-create shared resources $instanceGroups = $InputObject | Group-Object -Property { $_.Parent.Name } @@ -615,6 +616,7 @@ function Start-DbaDbEncryption { } Start-Sleep -Milliseconds 500 } + Write-Progress -Id 1 -Activity "Enabling encryption on $servername" -Completed $runspacePool.Close() $runspacePool.Dispose() diff --git a/public/Start-DbaMigration.ps1 b/public/Start-DbaMigration.ps1 index 8eedb493bbf2..e3a4dc567639 100644 --- a/public/Start-DbaMigration.ps1 +++ b/public/Start-DbaMigration.ps1 @@ -625,6 +625,7 @@ function Start-DbaMigration { Write-Message -Level Verbose -Message "Skipping SSIS catalog migration because the source instance does not have an SSISDB catalog." } } + Write-ProgressHelper -Completed } end { if ($dacOpened) { diff --git a/public/Stop-DbaDbEncryption.ps1 b/public/Stop-DbaDbEncryption.ps1 index 70d80c4c32bf..e852fa9357a1 100644 --- a/public/Stop-DbaDbEncryption.ps1 +++ b/public/Stop-DbaDbEncryption.ps1 @@ -110,6 +110,7 @@ function Stop-DbaDbEncryption { Stop-Function -Message "Failure" -ErrorRecord $_ -Continue } } + Write-ProgressHelper -Completed } else { # Parallel processing using runspaces $disableScript = { @@ -249,6 +250,7 @@ function Stop-DbaDbEncryption { } Start-Sleep -Milliseconds 500 } + Write-Progress -Id 1 -Activity "Disabling encryption" -Completed $runspacePool.Close() $runspacePool.Dispose() diff --git a/public/Sync-DbaAvailabilityGroup.ps1 b/public/Sync-DbaAvailabilityGroup.ps1 index 6c7508229b14..aba3cdd29609 100644 --- a/public/Sync-DbaAvailabilityGroup.ps1 +++ b/public/Sync-DbaAvailabilityGroup.ps1 @@ -425,6 +425,7 @@ function Sync-DbaAvailabilityGroup { Write-ProgressHelper -Activity $activity -StepNumber ($stepCounter++) -Message "Syncing login permissions" Sync-DbaLoginPermission -Source $server -Destination $secondaries -Login $Login -ExcludeLogin $ExcludeLogin } + Write-ProgressHelper -Activity $activity -Completed } } } \ No newline at end of file diff --git a/public/Sync-DbaLoginPermission.ps1 b/public/Sync-DbaLoginPermission.ps1 index 5b3a23fa582b..f5ceb70576bc 100644 --- a/public/Sync-DbaLoginPermission.ps1 +++ b/public/Sync-DbaLoginPermission.ps1 @@ -172,6 +172,7 @@ function Sync-DbaLoginPermission { Stop-Function -Message "Issue syncing permissions for login" -Target $loginName -ErrorRecord $_ -Continue } } + Write-ProgressHelper -Completed } } } \ No newline at end of file