PowerShell Logo Small

Write-Progress



This is the built-in help made by Microsoft for the command 'Write-Progress', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Displays a progress bar within a Windows PowerShell command window.

SYNTAX


Write-Progress [-Activity] <String> [[-Status] [<String>]] [[-Id] [<Int32>]] [-Completed] [-CurrentOperation [<String>]] [-InformationAction {SilentlyContinue | Stop |
Continue | Inquire | Ignore | Suspend}] [-InformationVariable [<System.String>]] [-ParentId [<Int32>]] [-PercentComplete [<Int32>]] [-SecondsRemaining [<Int32>]] [-SourceId
[<Int32>]] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Write-Progress cmdlet displays a progress bar in a Windows PowerShell command window that depicts the status of a running command or script. You can select the
indicators that the bar reflects and the text that appears above and below the progress bar.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=294031
Write-Debug
Write-Error
Write-Host
Write-Output
Write-Verbose
Write-Warning

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

PS C:\>for ($i = 1; $i -le 100; $i++ )
{write-progress -activity "Search in Progress" -status "$i% Complete:" -percentcomplete $i;}



This command displays the progress of a For loop that counts from 1 to 100. The Write-Progress command includes a status bar heading ("activity"), a status line, and the
variable $i (the counter in the For loop), which indicates the relative completeness of the task.










-------------------------- EXAMPLE 2 --------------------------

PS C:\>for($i = 1; $i -lt 101; $i++ )
{write-progress -activity Updating -status 'Progress->' -percentcomplete $i -currentOperation OuterLoop; `
for($j = 1; $j -lt 101; $j++ )
{write-progress -id 1 -activity Updating -status 'Progress' -percentcomplete $j -currentOperation InnerLoop} }

Updating
Progress ->
[ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo]
OutsideLoop
Updating
Progress
[oooooooooooooooooo ]
InnerLoop



This example displays the progress of two nested For loops, each of which is represented by a progress bar.

The Write-Progress command for the second progress bar includes the Id parameter that distinguishes it from the first progress bar. Without the Id parameter, the progress
bars would be superimposed on each other instead of being displayed one below the other.










-------------------------- EXAMPLE 3 --------------------------

PS C:\>$events = get-eventlog -logname system
PS C:\>$events | foreach-object -begin {clear-host;$i=0;$out=""} `
-process {if($_.message -like "*bios*") {$out=$out + $_.Message}; $i = $i+1;
write-progress -activity "Searching Events" -status "Progress:" -percentcomplete ($i/$events.count*100)} `
-end {$out}



This command displays the progress of a command to find the string "bios" in the System event log.

In the first line of the command, the Get-EventLog cmdlet gets the events in the System log and stores them in the $events variable.

In the second line, the events are piped to the ForEach-Object cmdlet. Before processing begins, the Clear-Host cmdlet is used to clear the screen, the $i counter variable
is set to zero, and the $out output variable is set to the empty string.

In the third line, which is the Process script block of the ForEach-Object cmdlet, the cmdlet searches the message property of each incoming object for "bios". If the string
is found, the message is added to $out. Then, the $i counter variable is incremented to record that another event has been examined.

The fourth line uses the Write-Progress cmdlet with values for the Activity and Status text fields that create the first and second lines of the progress bar heading,
respectively. The PercentComplete parameter value is calculated by dividing the number of events that have been processed ($i) by the total number of events retrieved
($events.count) and then multiplying that result by 100.

In the last line, the End parameter of the ForEach-Object cmdlet is used to display the messages that are stored in the $out variable.