Function/Tool/Start-F2BSleep.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function Start-F2BSleep (){
    <#
        .SYNOPSIS
            Suspends the activity in a script or session for the specified period of time.

        .DESCRIPTION
            The New-Sleep cmdlet suspends the activity in a script or session for the specified period of time.
            You can use it for many tasks, such as waiting for an operation to complete or pausing before repeating an operation.

        .NOTES
            Author : Thomas ILLIET, contact@thomas-illiet.fr
            Date : 2017-05-10
            Last Update : 2018-01-08
            Version : 1.0.2

        .PARAMETER S
            Time to wait

        .PARAMETER Message
            Message you want to display

        .EXAMPLE
            New-Sleep -S 60 -Message "wait and see"

        .EXAMPLE
            New-Sleep -S 60
    #>

    [cmdletbinding()]
    param
    (
        [parameter(Mandatory=$true)]
        [int]$S,
        [parameter(Mandatory=$false)]
        [string]$Message="Wait"
    )
    for ($i = 1; $i -lt $s; $i++) 
    {
        [int]$TimeLeft = $s - $i
        Write-Progress -Activity $message -PercentComplete (100 / $s * $i) -CurrentOperation "$TimeLeft seconds left" -Status "Please wait"
        Start-Sleep -s 1
    }
    Write-Progress -Completed $true -Status "Please wait"
}