多个Powershell进度条(嵌套?)

K.B*_*ell 9 powershell progress-bar

我正在寻找一种方法来显示多个进度条,一个用于外部循环,一个用于内部.我有一个脚本循环遍历一个自定义对象的大列表,并且对于每个对象,我有一个内部循环,它对作为这些对象的属性的列表执行操作.

脚本示例:

$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
        }
    }
} 
Run Code Online (Sandbox Code Playgroud)

显示进度功能:

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 + "%")
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我正在寻找的一个快速示例: ProgressExample

Joh*_*aan 16

您可以使用该参数-ParentId-Id完成该操作.在外循环中,您可以分配ID 1,在内循环中,您可以指定ParentId值1.


maz*_*zzy 6

https://www.powershellgallery.com/packages/write-ProgressEx

https://github.com/mazzy-ax/Write-ProgressEx

样品:

$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
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述