function Start-cpSleepProgressBar {
<#
.SYNOPSIS
This feature is the control of the function Write-Progress Bar simplified.
.DESCRIPTION
This feature is the control of the function Write-Progress Bar simplified.
.EXAMPLE
Start-cpSleepProgressBar -Activity "test" -ProgressFlow Increasingly -TimeIn Seconds -Value 10
.EXAMPLE
Start-cpSleepProgressBar -Activity "test" -ProgressFlow Decreasing -TimeIn Seconds -Value 10
.EXAMPLE
Start-cpSleepProgressBar -Activity "test" -ProgressFlow Increasingly -TimeIn Seconds -Value 10 -ReturnCode
.NOTES
Create by : T. Del Greco
Date : 03.03.2018
#>
[CmdletBinding()]
[OutputType()]
PARAM (
[parameter(Mandatory=$false)][System.String]$Activity = "Please wait.",
[parameter(Mandatory=$false)][ValidateSet('Increasingly','Decreasing')][System.String]$ProgressFlow = 'Increasingly',
[parameter(Mandatory=$false)][ValidateSet('Hours','Minutes','Seconds')][System.String]$TimeIn = 'Seconds',
[parameter(Mandatory=$true)][System.Int32]$Value,
[parameter(Mandatory=$false)][System.Boolean]$ReturnCode
)
BEGIN {
switch ($TimeIn) {
'Seconds' {
$SleepSeconds = $Value
}
'Minutes' {
$SleepSeconds = $Value * 60
}
'Hours' {
$SleepSeconds = $Value * 60 * 60
}
}
}
PROCESS {
switch ($ProgressFlow) {
'Increasingly' {
for($Count=0; $Count -lt $SleepSeconds; $Count++) {
Write-Progress -Activity $Activity -Status "Sleeping" -SecondsRemaining $Count -PercentComplete ($Count/$SleepSeconds*100)
Start-Sleep -Seconds 1
}
}
'Decreasing' {
for($Count=$SleepSeconds; $Count -gt 0; $Count--) {
Write-Progress -Activity $Activity -Status "Sleeping" -SecondsRemaining $Count -PercentComplete ($Count/$SleepSeconds*100)
Start-Sleep -Seconds 1
}
}
}
}
END {
if ($ReturnCode) {
return $true
}
}
}