-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
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.
- 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?
- Why do the progress bars accumulate when invoking
Backup-SqlDatabasebut do not accumulate when paying back the same records viaWrite-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.xmlArtifacts
- 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:
Actual behavior
The progress bars accumulate:
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

