Skip to content

Write-Progress does not work correctly with nested operations. #5370

@LethiferousMoose

Description

@LethiferousMoose

Steps to reproduce

  1. Create and inner and outer loop
  2. Write-Progress at the beginning of outer loop and inner loop, using reference to parent ID for inner loop
  3. Perform some lengthy operation in inner loop, then update inner progress
  4. After inner loop completes, update outer progress
[int] $innerPercent = 0
[int] $outerPercent = 0

for ($i = 0; $i -lt 2; $i++) {
    Write-Progress -Activity "Testing" -Status "Progress:" -Id 1 -PercentComplete $outerPercent -CurrentOperation "Outer : $i"

    for ($j = 0; $j -lt 5; $j++) {
        # This has no effect
        Write-Progress -Activity "Testing" -Status "Progress:" -Id 2 -PercentComplete $innerPercent -CurrentOperation "Inner : $j"
        # Performing some long operation here.
        Start-Sleep 5
        $innerPercent = ($j + 1) / 5 * 100
        Write-Progress -Activity "Testing" -Status "Progress:" -Id 2 -PercentComplete $innerPercent -CurrentOperation "Inner : $j"
    }

    # Sleeping to allow final Write-Progress of inner loop to render
    Start-Sleep 5
    # Hide inner progress
    Write-Progress -Activity "Testing" -Id 2 -Completed

    $outerPercent = ($i + 1) / 2 * 100
    # This has no effect
    Write-Progress -Activity "Testing" -Status "Progress:" -Id 1 -PercentComplete $outerPercent -CurrentOperation "Outer : $i"
}

# Sleeping to allow final Write-Progress of outer loop to render
Start-Sleep 5
# Hide outer progress
Write-Progress -Activity "Testing" -Id 1 -Completed

Expected behavior

All Write-Progress calls to update the progress on the console.

Actual behavior

- The Write-Progress call before the operation in the inner loop does not  render.
- The final Write-Progress call after the outer loop terminates does not render.

Note: This worked correctly in 5.1 and may be related to issue #3366

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.0-beta.9
PSEdition                      Core
GitCommitId                    v6.0.0-beta.9
OS                             Microsoft Windows 10.0.15063
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-BugIssue has been identified as a bug in the productResolution-DuplicateThe issue is a duplicate.WG-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions