I'm looking for a way to display multiple progress bars, one for an outer loop and one for an inner. I have a script that Loops through a big list of custom objects, and for each of those objects I have an inner loop that performs actions on a list that is an attribute of those objects.
Script Example:
$ListOfIDs.Keys |
Show-Progress | #Outer Loop - ProgressBar1
% {
    $entityName = $_
    $TableIndex = $ListOfEntities.Name.IndexOf($entityName)
    $TableNameList = $ListOfEntities[$TableIndex].Group.RoleTable
    $ListOfIDS[$_] |
    Show-Progress | #Inner Loop - ProgressBar2
    % {
        $ID = $_.ID
        [PSCustomObject] @{
            EntityName = $entityName
            Id = $ID
            Roles =  $TableNameList | Function-FooBar -ID $ID
        }
    }
} 
Show-Progress Function:
function Show-Progress
{
[CmdletBinding()]
param (
    [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
    [PSObject[]]$InputObject
)
    [int]$TotItems = $Input.Count
    [int]$Count = 0
    $Input|foreach {
        $_
        $Count++
        [int]$PercentComplete = ($Count/$TotItems* 100)
        Write-Progress -Activity "Processing items" -PercentComplete $PercentComplete -Status ("Working - " + $PercentComplete + "%")
    }
}
Here is a quick example of what I am looking for : 
You can use the parameter -ParentId and -Id to accomplish that. At the Outer Loop you assign the ID 1, and at the Inner Loop you specify as ParentId the value 1.
https://www.powershellgallery.com/packages/write-ProgressEx
https://github.com/mazzy-ax/Write-ProgressEx
sample:
$outer = 1..20
$inner = 1..50
write-ProgressEx "pipe nodes" -Total $outer.Count
$outer | write-ProgressEx -Status "outer" | ForEach-Object {
    write-ProgressEx "pipe names" -Total $inner.Count -id 1
    $inner | write-ProgressEx -id 1 -status "inner" | ForEach-Object {
        # ....
    }
}
write-ProgressEx #close all progress bars

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With