Private/Write-RaidinessProgress.ps1
|
<# One place that decides how the bars nest. Write-Progress bars are addressed by number, and a number used twice makes two bars fight over one line. Fixing the scheme here means a caller never has to know what the layer above it used: Id 1 the run connect -> collect -> modules -> export Id 2 the phase collector 17 of 52, module 3 of 5 Id 3 the unit evidence item, page 4 of a paged source, site 9 of 15 -Quiet drops the bars for an unattended run without every caller wrapping its progress in an if. #> function Write-RaidinessProgress { [CmdletBinding()] param( [Parameter(Mandatory = $true)] [ValidateRange(1, 3)] [int] $Id, [int] $ParentId = -1, [Parameter(Mandatory = $true)] [string] $Activity, [string] $Status, [Nullable[int]] $PercentComplete, [int] $SecondsRemaining = -1, [switch] $Completed, [switch] $Quiet ) if ($Quiet) { return } $arguments = @{ Id = $Id; Activity = $Activity } if ($ParentId -ge 0) { $arguments.ParentId = $ParentId } if ($Completed) { Write-Progress @arguments -Completed return } if ($Status) { $arguments.Status = $Status } if ($null -ne $PercentComplete) { $arguments.PercentComplete = [math]::Min([math]::Max($PercentComplete, 0), 100) } if ($SecondsRemaining -ge 0) { $arguments.SecondsRemaining = $SecondsRemaining } Write-Progress @arguments } |