powershell progress bar 1

powershell progress bar

foreach ($i in 1..100) {
  Write-Progress -Activity "Testing" -Status "$i% Complete:" -PercentComplete $i
  Start-Sleep -Milliseconds 100
}

Here is what the above code is Doing:
1. The first line is just a comment.
2. The second line is a for loop that will run 100 times.
3. The third line is a call to the Write-Progress cmdlet.
4. The fourth line is a call to the Start-Sleep cmdlet.

The Write-Progress cmdlet is used to display a progress bar in the PowerShell console.
The Start-Sleep cmdlet is used to pause the script for a specified amount of time.

The Write-Progress cmdlet has four parameters:
-Activity: This is the name of the activity that is being tracked.
-Status: This is the status of the activity.
-PercentComplete: This is the percentage of the activity that has been completed.
-CurrentOperation: This is the current operation that is being performed.

The Start-Sleep cmdlet has one parameter:
-Milliseconds: This is the number of milliseconds that the script should pause for.

Similar Posts