Private/Helpers/Show-ProgressHelper.ps1
|
function Show-ProgressHelper { [CmdletBinding()] param( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] # Add validation [string]$Activity, # Add default value even though it's mandatory [string]$Status = "Processing...", [int]$PercentComplete = -1, [string]$CurrentOperation = "", [switch]$Completed ) # Additional validation if ([string]::IsNullOrWhiteSpace($Activity)) { $Activity = "Processing" # Fallback value } if ($Completed) { Write-Progress -Activity $Activity -Completed } else { $progressParams = @{ Activity = $Activity Status = $Status } if ($PercentComplete -ge 0) { $progressParams['PercentComplete'] = $PercentComplete } if (![string]::IsNullOrWhiteSpace($CurrentOperation)) { $progressParams['CurrentOperation'] = $CurrentOperation } Write-Progress @progressParams } } |