CmdID

CmdID / PowerShell / Cmdlets / Write

Write-Progress

Displays a progress bar within a PowerShell command window. PowerShell reference

From the PowerShell reference 9 parameters

Opens CmdID with your command, read as PowerShell. It is read in your browser and sent nowhere.

What it does

from the PowerShell reference, CC BY 4.0

Displays a progress bar within a PowerShell command window. The Write-Progress cmdlet displays a progress bar in a 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.

Write-Progress [-Activity] <String> [[-Status] <String>] [[-Id] <Int32>] [-PercentComplete <Int32>] [-SecondsRemaining <Int32>] [-CurrentOperation <String>] [-ParentId <Int32>] [-Completed] [-SourceId <Int32>] [<CommonParameters>]

Display the progress of a for loop

for ($i = 1; $i -le 100; $i++ ) { Write-Progress -Activity "Search in Progress" -Status "$i% Complete:" -PercentComplete $i Start-Sleep -Milliseconds 250 }Identify

Display the progress of nested for loops

for($I = 0; $I -lt 10; $I++ ) { $OuterLoopProgressParameters = @{ Activity = 'Updating' Status = 'Progress->' PercentComplete = $I * 10 CurrentOperation = 'OuterLoop' } Write-Progress @OuterLoopProgressParameters for($j = 1; $j -lt 101; $j++ ) { $InnerLoopProgressParameters = @{ ID = 1 Activity = 'Updating' Status = 'Progress' PercentComplete = $j CurrentOperation = 'InnerLoop' } Write-Progress @InnerLoopProgressParameters Start-Sleep -Milliseconds 25 } }Identify

Display the progress while searching for a string

# Use Get-EventLog to get the events in the System log and store them in the $Events variable. $Events = Get-EventLog -LogName System # Pipe the events to the ForEach-Object cmdlet. $Events | ForEach-Object -Begin { # In the Begin block, use Clear-Host to clear the screen. Clear-Host # Set the $i counter variable to zero. $i = 0 # Set the $out variable to an empty string. $out = "" } -Process { # In the Process scriptblock search the message property of each incoming object for "bios". if($_.Message -like "bios") { # Append the matching message to the out variable. $out=$out + $_.Message } # Increment the $i counter variable which is used to create the progress bar. $i = $i+1 # Determine the completion percentage $Completed = ($i/$Events.Count) * 100 # Use Write-Progress to output a progress bar. # The Activity and Status parameters create the first and second lines of the progress bar # heading, respectively. Write-Progress -Activity "Searching Events" -Status "Progress:" -PercentComplete $Completed } -End { # Display the matching messages using the out variable. $out }Identify

Trips 1 Sigma rule: mediumEventLog Query Requests By Builtin Utilities by Ali Alwashali, Nasreddine Bencherchali (Nextron Systems)

Display progress for each level of a nested process

foreach ( $i in 1..10 ) { Write-Progress -Id 0 "Step $i" foreach ( $j in 1..10 ) { Write-Progress -Id 1 -ParentId 0 "Step $i - Substep $j" foreach ( $k in 1..10 ) { Write-Progress -Id 2 -ParentId 1 "Step $i - Substep $j - iteration $k" Start-Sleep -Milliseconds 150 } } }Identify

Its page in the reference: Write-Progress.

Parameters

9 in the PowerShell reference
-ActivitySpecifies the first line of text in the heading above the status bar. This text describes the activity whose progress is being reported.
-CompletedIndicates whether the progress bar is visible. If this parameter is omitted, Write-Progress displays progress information.
-CurrentOperationSpecifies the line of text below the progress bar. This text describes the operation that's currently taking place.
-IdSpecifies an ID that distinguishes each progress bar from the others. Use this parameter when you are creating more than one progress bar in a single command. If the progress bars don't have different IDs, they're superimposed instead of being displayed in a series. Negative values aren't allowed.
-ParentIdSpecifies the parent activity of the current activity. Use the value -1 if the current activity has no parent activity.
-PercentCompleteSpecifies the percentage of the activity that's completed. Use the value -1 if the percentage complete is unknown or not applicable.
-SecondsRemainingSpecifies 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.
-SourceIdSpecifies the source of the record. You can use this in place of Id but can't be used with other parameters like ParentId.
-StatusSpecifies the second line of text in the heading above the status bar. This text describes current state of the activity.