Skip to content

Write-ProgressEx is a powershell advanced function that extends the Write-Progress cmdlet.

License

Notifications You must be signed in to change notification settings

mazzy-ax/Write-ProgressEx

Repository files navigation

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.

[email protected]

About

Write-ProgressEx is a powershell advanced function that extends the Write-Progress cmdlet.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published