I am re-writing the Write-Progress function to work better with my script and to accomplish this I am joining all the arguments into a string and then trying to use it on the command however it is not working.
Function
Function Update-Progress {
Param (
[String] $Activity,
[Bool] $Completed,
[String] $CurrentOperation,
[Int] $ID,
[Int] $ParentID,
[Int] $PercentComplete,
[Int] $SecondsRemaining,
[Int] $SourceID,
[String] $Status
)
If ($htDisplay.WriteProgress.Enable -EQ $True -AND $htDisplay.WriteProgress.StopWatch.Elapsed.TotalMilliseconds -ge 500) {
$Parameters = New-Object System.Text.StringBuilder
IF (isNull($Activity)) { Write-Error "Activity is Required" } Else { $Null = $Parameters.Append("-Activity `"$Activity`"") }
IF (!(isNull($Completed))) { $Null = $Parameters.Append(" -Completed") }
IF (!(isNull($CurrentOperation))) { $Null = $Parameters.Append(" -CurrentOperation `"$CurrentOperation`"") }
IF (!(isNull($ID))) { $Null = $Parameters.Append(" -ID `"$ID`"") }
IF (!(isNull($ParentID))) { $Null = $Parameters.Append(" -ParentID `"$ParentID`"") }
IF (!(isNull($PercentComplete))) { $Null = $Parameters.Append(" -PercentComplete `"$PercentComplete`"") }
IF (!(isNull($SecondsRemaining))) { $Null = $Parameters.Append(" -SecondsRemaining `"$SecondsRemaining`"") }
IF (!(isNull($SourceID))) { $Null = $Parameters.Append("-SourceID `"$SourceID`"") }
IF (!(isNull($Status))) { $Null = $Parameters.Append(" -Status `"$Status`"") }
"Write-Progress $Parameters"
Write-Progress $Parameters
$htDisplay.WriteProgress.StopWatch.Reset()
$htDisplay.WriteProgress.StopWatch.Start()
}
}
Command Calling Function
Update-Progress -ID 1 -Activity "Preloading threads" -Status "Starting Job $($htConfig.MultiThread.Jobs.count)"
Error - The Progress bar displays
-Activity "Preloading Threads" -ID "1" -Status "Starting Job #"
Write-Host of the exact command shows the following so the syntax is correct, just need to figure out how to process the variable as all the parameters instead of just the activity param.
Write-Progress -Activity "Preloading threads" -ID "1" -Status "Starting Job 2"