55 lines
1.5 KiB
PowerShell
55 lines
1.5 KiB
PowerShell
function Write-ProgressHelper {
|
|
param (
|
|
[int]$StepNumber = 1,
|
|
[string]$Status = "Progress",
|
|
[string]$Activity,
|
|
[string]$CurrentOperation,
|
|
[int]$PercentComplete = 0
|
|
)
|
|
|
|
$activityId = 0
|
|
$parentId = 0
|
|
$callstackFunctions = (Get-CallstackParentFunctionNames)
|
|
# Don't worry about this function or the one we just called to get the stack, or the parent of this one, we handle that next
|
|
for($i = 0; $i -lt ($callstackFunctions.Count - 1); $i++) {
|
|
# this will always be one less than our current depth
|
|
$function = $callstackFunctions[$i]
|
|
if ((Get-FunctionWriteProgressHelperCalls $function) -gt 0) {
|
|
$parentId = $activityId
|
|
$activityId++
|
|
}
|
|
}
|
|
|
|
$PercentNotSpecified = $false
|
|
if ($PercentComplete -eq 0) {
|
|
$PercentNotSpecified = $true
|
|
$stepCounter = (Get-FunctionWriteProgressHelperCalls (Get-GrandParentFunctionName))
|
|
$PercentComplete = (($StepNumber / $stepCounter) * 100)
|
|
}
|
|
|
|
$paramSplat = @{
|
|
Id = $activityId
|
|
Status = $Status
|
|
PercentComplete = $PercentComplete
|
|
}
|
|
|
|
if (![string]::IsNullOrWhiteSpace($Activity)) {
|
|
$paramSplat["Activity"] = $Activity
|
|
}
|
|
|
|
if (![string]::IsNullOrWhiteSpace($CurrentOperation)) {
|
|
$paramSplat["CurrentOperation"] = $CurrentOperation
|
|
}
|
|
|
|
if ($parentId -gt 0) {
|
|
$paramSplat["ParentId"] = $parentId
|
|
}
|
|
|
|
Write-Progress @paramSplat
|
|
|
|
if ($PercentNotSpecified) {
|
|
return $StepNumber++
|
|
}
|
|
}
|
|
|