Tuesday, 27 September 2022

Powershell Start-Sleep

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/start-sleep?view=powershell-7.2&viewFallbackFrom=powershell-7.1 

Start-Sleep

Suspends the activity in a script or session for the specified period of time.

Syntax

PowerShell
Start-Sleep
     [-Seconds] <Double>
     [<CommonParameters>]
PowerShell
Start-Sleep
     -Milliseconds <Int32>
     [<CommonParameters>]

Description

The Start-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.

Examples

Example 1: Pause execution for 1.5 seconds

In this example, the execution of commands pauses for one and one-half seconds.

PowerShell
Start-Sleep -Seconds 1.5

Example 2: Pause execution at the command line

This example shows that execution is paused for 5 seconds when run from the command line.

PowerShell
PS> Get-Date; Start-Sleep -Seconds 5; Get-Date

Friday, May 13, 2022 9:38:15 AM
Friday, May 13, 2022 9:38:20 AM

PowerShell cannot execute the second Get-Date command until the sleep timer expires.

Parameters

-Milliseconds

Specifies how long the resource sleeps in milliseconds. The parameter can be abbreviated as m.

Type:Int32
Aliases:ms
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False

-Seconds

Specifies how long the resource sleeps in seconds. You can omit the parameter name or you can abbreviate it as s. Beginning in PowerShell 6.2.0, this parameter now accepts fractional values.

Type:Double
Position:0
Default value:None
Accept pipeline input:True
Accept wildcard characters:False

Inputs

Int32

You can pipe the number of seconds to Start-Sleep.

Outputs

None

This cmdlet does not return any output.

Notes

  • You can also refer to Start-Sleep by its built-in alias, sleep. For more information, see about_Aliases.
  • Ctrl+C breaks out of Start-Sleep.
  • Ctrl+C does not break out of [Threading.Thread]::Sleep. For more information, see Thread.Sleep Method.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.