Skip to content

Progress bar remains despite Completed record in progress stream (now with portable repro) #12541

@alx9r

Description

@alx9r

I've noticed occasions where PowerShell continues to show a progress bar despite that the activity has completed. That can be merely confusing on short runs, but it becomes inscrutable for long-running scripts because the progress bars eventually accumulate until they fill most of the console and then jump around (see also #7507).

In some cases a progress bar remains because the offending command simply does not write a "Completed" record. That can be determined by examining PowerShell.Streams.Progress. In this case, however, it looks to me that correctly-formatted "Completed" records are indeed written to the progress stream.

  1. In what conditions should I expect PowerShell to stop displaying a progress bar? Is it simply a "Completed" record with a matching ActivityId? Or are there other conditions that also have to be met?
  2. Why do the progress bars accumulate when invoking Backup-SqlDatabase but do not accumulate when paying back the same records via Write-Progress?

Steps to reproduce

Note: I had originally posted a repro that wasn't portable. See the revision history of this post for that repro.

Prerequisites

  • SqlServer module
  • A test database instance with an empty database, and permissions to perform a backup.

Script

Import-Module SqlServer -PassThru | select Name,Version | Out-String | Write-Host
$sb = {
    1..10 | % {
        Backup-SqlDatabase TEST_DB_0178b0 -ServerInstance .\TEST_INST_ba7dec
        Write-Progress 'Backup complete' -Id 1 -Completed
    }
}
. $sb
$ps = [powershell]::Create().AddScript($sb)
$ps.Invoke() | Out-Null
$ps.Streams.Progress |
    ? {$_.Activity -like '*Back*' } |
    Select-Object ActivityId,RecordType,Activity
$ps.Streams.Progress | Export-Clixml .\progress.xml

Artifacts

  • progress.xml - captured by above script
  • playback.ps1 - used to "playback" the progress captured and demonstrate the "expected" behavior

Output of progress stream (... indicates repetition of the same record):


ActivityId RecordType Activity
---------- ---------- --------
         1 Processing Backing up (Database: 'TEST_DB_0178b0' ; Server: 'DT30\TEST_INST_ba7dec' ; Action = 'Database')
...
         1  Completed Backup complete
         1 Processing Backing up (Database: 'TEST_DB_0178b0' ; Server: 'DT30\TEST_INST_ba7dec' ; Action = 'Database')
...
         1  Completed Backup complete
         1 Processing Backing up (Database: 'TEST_DB_0178b0' ; Server: 'DT30\TEST_INST_ba7dec' ; Action = 'Database')
...
         1  Completed Backup complete
         1 Processing Backing up (Database: 'TEST_DB_0178b0' ; Server: 'DT30\TEST_INST_ba7dec' ; Action = 'Database')
...
         1  Completed Backup complete
         1 Processing Backing up (Database: 'TEST_DB_0178b0' ; Server: 'DT30\TEST_INST_ba7dec' ; Action = 'Database')
...
         1  Completed Backup complete
         1 Processing Backing up (Database: 'TEST_DB_0178b0' ; Server: 'DT30\TEST_INST_ba7dec' ; Action = 'Database')
...
         1  Completed Backup complete
         1 Processing Backing up (Database: 'TEST_DB_0178b0' ; Server: 'DT30\TEST_INST_ba7dec' ; Action = 'Database')
...
         1  Completed Backup complete
         1 Processing Backing up (Database: 'TEST_DB_0178b0' ; Server: 'DT30\TEST_INST_ba7dec' ; Action = 'Database')
...
         1  Completed Backup complete
         1 Processing Backing up (Database: 'TEST_DB_0178b0' ; Server: 'DT30\TEST_INST_ba7dec' ; Action = 'Database')
...
         1  Completed Backup complete

Expected behavior

I expect the behavior of the progress bar to be like this in that they do not accumulate:

expected

Actual behavior

The progress bars accumulate:

actual

Environment data


Name                           Value
----                           -----
PSVersion                      7.1.0-preview.2
PSEdition                      Core
GitCommitId                    7.1.0-preview.2
OS                             Microsoft Windows 6.3.9600
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0


Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions