powershell - How to get progress information resulting from Write-Progress? -


i have powershell function calls write-progress. in function, state of displayed progress. possible query state of displayed progress?

the use case this:

  • i have function calls function b 10 times.
  • each time function calls function b, write-progress called update -percentcomplete.
  • within function b, update -percentcomplete of progress, don't know current percent complete is. don't want pass around "progress" object b if can query displayed progress object.

i have tagged because environment is.

i have tried looking in $host variable, $host.ui , $host.ui.rawui , not find want.

so else interested, ended defining these 2 functions in module (kudos hal9256 inspiration):

function get-progress {     [cmdletbinding()]     param()      if (-not $global:progress) {         $global:progress = new-object psobject -property @{             'activity' = $null             'status' = $null             'id' = $null             'completed' = $null             'currentoperation' = $null             'parentid' = $null             'percentcomplete' = $null             'secondsremaining' = $null             'sourceid' = $null         }     }      $global:progress }     function show-progress {     [cmdletbinding()]     param()      $progress = $global:progress      $properties = $progress.psobject.properties | {$_.membertype -eq 'noteproperty'}      $parameters = @{}     foreach ($property in $properties) {         if ($property.value) {             $parameters[$property.name] = $property.value         }     }      if ($parameters.count) {         write-progress @parameters     } } 

there's nothing query. must keep track of/calculate percentage , pass cmdlet, otherwise write-progress wouldn't know display.

give function b additional parameter , add counter function a:

function {   $i = 1   1..10 | % {     b (10 * $i)     $i++   } }  function b($p) {   write-progress -activity 'foo' -percentcomplete $p } 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -