Display a progress bar.
Syntax
Write-Progress [-activity] string [-status] string [[-id] int]
[-percentComplete int] [-secondsRemaining int]
[-currentOperation string] [-parentId int]
[-completed] [-sourceId int] [CommonParameters]
Key
-activity string
A string that describes the activity about which progress is being reported.
Will appear as the first heading above the progress bar.
-status string
A string that describes current state of the activity about which progress
is being reported. Will appear as the second heading above the progress bar.
-id int
The activity identifier for this progress record.
-percentComplete int
The percentage of the activity that is completed.
Use the value -1 if the percentage is unknown or not applicable.
-secondsRemaining int
The projected number of seconds remaining until the activity is completed.
Use the value -1 if the number of seconds remaining is unknown or not applicable.
-currentOperation string
Describes the operation that is currently taking place.
-parentId int
The parent activity of the current activity.
Use the value -1 if the current activity has no parent activity.
-completed
Hide the progress bar, to indicate the activity is complete.
-sourceId int
Identify the source of the record
CommonParameters:
-Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable,
-OutBuffer -OutVariable.
Write-Progress displays a progress bar in a PowerShell command window that depicts the status of a running command or script.
Examples
Display progress of a for loop:
PS C:\> for($i = 1; $i -lt 101; $i++ )
{for($j=0;$j -lt 10000;$j++) {} write-progress "Search in Progress" "% Complete:" -perc $i;}
Display progress while searching through the system event log messages:
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}
“I don't like to write, but I love to have written” ~ Michael Kanin
Related PowerShell Cmdlets:
Write-Debug - Write a debug message to the host display.
Write-Error - Write an object to the error pipeline.
Write-Host - Display objects through the host user interface.
Write-Output - Write an object to the pipeline.
Write-Verbose - Write a string to the host’s verbose display.
Write-Warning - Write a warning message.