November 2018
Intermediate to advanced
566 pages
17h 15m
English
Modify the script we used in the previous recipe, Adding default values to a parameter, to the following:
function Start-Count {
param (
# The current time, or the starting point
[Parameter(Mandatory=$false)]
[Alias("CT", "From")]
[int]
$CurrentTime=0,
# The total number of seconds to count
[Parameter(Mandatory=$false, Position=1)]
[Alias("TT", "To")]
[ValidateSet(5, 10, 15, 20)]
[int]
$TotalTime=10
)
while ($CurrentTime -le $TotalTime) {
Write-Progress -Activity "Counting to $TotalTime" -Status "Counting: $CurrentTime seconds" -PercentComplete ($CurrentTime / $TotalTime * 100)
Start-Sleep 1
$CurrentTime++
}
}
Run the following command and read the error:
PS> Start-Count -TotalTime 6
Read now
Unlock full access