Write-ProgressEx

Write-ProgressEx extends the functionality of the standard cmdlet. Write-ProgressEx is a powershell advanced function that provide a simple way to show ProgressBars, PercentComplete and SecondsRemaining.


Keywords
Progress, ProgressBar, Write-Progress, powershell
License
MIT
Install
Install-Package Write-ProgressEx -Version 0.22.0

Documentation

Write-ProgressEx – extended write-progress cmdlet

Build status PowerShell Gallery NuGet Write-ProgressEx icon

Write-ProgressEx extends the functionality of the standard powershell cmdlet. Write-ProgressEx is a powershell advanced function that provides a simple way to show ProgressBars with PercentComplete and SecondsRemaining.

The cmdlet:

  • works with pipe;
  • works with empty activity string;
  • completes all inner progresses if no parameters;
  • automatically completes with pipe;
  • automatically calculates percents, remaining seconds and elapsed time;
  • automatically displays current iteration and totals on progress bar;
  • automatically displays info with a progress bar and at the console title;
  • automatically set parent id for a inner loop;
  • stores totals, current values and actual parameters into the module hashtable;
  • provides get/set cmdlets to access actual parameters;
  • uses script blocks to show messages with date, time, iterations and elapsed time on events:
    • first iteration;
    • activity changed;
    • status changed;
    • completed.
  • provides a counter functional. See Write-ProgressEx as a counter;
  • uses the caller function name or the caller script file name as the Activity;
  • accepts -ShowProgressBar Auto parameter to reduce the overhead for redrawing a screen. It recognizes None and Force values also.

Note: the function is not safe with multi-thread.

Examples

A pipe and a simple loop:

$range1 = 1..20
$range1 | Write-ProgressEx "loop 1" -Total $range1.Count -ShowMessages | ForEach-Object {
    # ....
}

$range2 = 1..15
$range2 | ForEach-Object {
    # ....
    Write-ProgressEx "loop 2" -Total $range2.Count -Increment
}

Write-ProgressEx #close all progress bars

Pipes in nested loops:

$outer = 1..20
$inner = 1..50

$outer | Write-ProgressEx "pipe nodes" -Status "outer" -Total $outer.Count -ShowMessages | ForEach-Object {
    $inner | Write-ProgressEx "pipe names" -id 1 -Status "inner" -Total $inner.Count | ForEach-Object {
        # ....
    }
}

screenshot: Write-ProgressEx

screenshot: Result messages

A long time command:

$path = $env:homepath
$files = Get-ChildItem $path -Recurse | Write-ProgressEx $path

More samples are in the folder Examples.

Installation

Automatic install Write-ProgressEx module from the PowerShell Gallery:

Install-Module -Name Write-ProgressEx
Import-Module Write-ProgressEx

Automatic install Write-ProgressEx module from the NuGet.org:

Install-Package -Name Write-ProgressEx
Import-Module Write-ProgressEx

or manual:

  • Download and unblock the latest .zip file.
  • Extract the .zip into your $PSModulePath, e.g. ~\Documents\WindowsPowerShell\Modules.
  • Ensure the extracted folder is named Write-ProgressEx.
  • Set an execution policy to RemoteSigned or Unrestricted to execute not signed modules Set-ExecutionPolicy RemoteSigned.
  • Run Import-Module Write-ProgressEx.

Known issues

  • Unable to import module on case-sensitive file systems. Thanks @jasonchester for the workaround

Changelog

License

This project is released under the licensed under the MIT License.

mazzy@mazzy.ru