November 2018
Intermediate to advanced
566 pages
17h 15m
English
This is a percentage-based progress writing. Therefore, we need to know the total time beforehand. We will calculate the percentage based on the elapsed time, and we will pass it to the Write-Progress cmdlet, which we will use to write the progress of our task. Follow these steps to get started:
$TotalTime = 25
$CurrentTime = 0
do {
Write-Progress -Activity 'Counting to 25' -Status "Elapsed time: $CurrentTime seconds" -PercentComplete ($CurrentTime / $TotalTime * 100)
Start-Sleep 1
$CurrentTime++
} until ($CurrentTime -eq $TotalTime)
Read now
Unlock full access