Sto cercando un modo per visualizzare più barre di avanzamento, una per un ciclo esterno e una per un interno. Ho uno script che scorre in una grande lista di oggetti personalizzati, e per ognuno di questi oggetti ho un ciclo interno che esegue azioni su un elenco che è un attributo di quegli oggetti.Barre di avanzamento Powershell multiple (nidificate?)
Esempio di script:
$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 Funzione:
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 + "%")
}
}
Ecco un rapido esempio di quello che sto cercando:
Ciò realizza ciò che volevo perfettamente, non posso credere che non ho mai notato la proprietà dei genitori, mi sento stupido ora. Grazie per l'aiuto! –
Prego :) –