Start-Sleep
Suspends the activity in a script or session for the specified period of time.
Синтаксис
Seconds (по умолчанию)
Start-Sleep
[-Seconds] <Double>
[<CommonParameters>]
Milliseconds
Start-Sleep
-Milliseconds <Int32>
[<CommonParameters>]
FromTimeSpan
Start-Sleep
-Duration <TimeSpan>
[<CommonParameters>]
Описание
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.
Примеры
Example 1: Pause execution for 1.5 seconds
In this example, the execution of commands pauses for one and one-half seconds.
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.
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.
Example 3: Sleep commands using a **TimeSpan**
This example makes all the commands in the session sleep for 30 seconds.
Start-Sleep -Duration (New-TimeSpan -Seconds 30)
Параметры
-Duration
Uses a TimeSpan object to specify how long the resource sleeps in milliseconds. The value must
not be a negative TimeSpan and must not exceed [int]::MaxValue
milliseconds.
This parameter was added in PowerShell 7.3.
Свойства параметра
Тип: | TimeSpan |
Default value: | None |
Поддерживаются подстановочные знаки: | False |
DontShow: | False |
Aliases: | ts |
Наборы параметров
FromTimeSpan
Position: | Named |
Обязательно: | True |
Значение из конвейера: | True |
Значение из конвейера по имени свойства: | True |
Значение из оставшихся аргументов: | False |
-Milliseconds
Specifies how long the resource sleeps in milliseconds. The parameter can be abbreviated as m.
Свойства параметра
Тип: | Int32 |
Default value: | None |
Поддерживаются подстановочные знаки: | False |
DontShow: | False |
Aliases: | ms |
Наборы параметров
Milliseconds
Position: | Named |
Обязательно: | True |
Значение из конвейера: | False |
Значение из конвейера по имени свойства: | True |
Значение из оставшихся аргументов: | 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.
Свойства параметра
Тип: | Double |
Default value: | None |
Поддерживаются подстановочные знаки: | False |
DontShow: | False |
Наборы параметров
Seconds
Position: | 0 |
Обязательно: | True |
Значение из конвейера: | True |
Значение из конвейера по имени свойства: | True |
Значение из оставшихся аргументов: | False |
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Входные данные
Int32
You can pipe the number of seconds to this cmdlet.
Выходные данные
None
This cmdlet returns no output.
Примечания
PowerShell includes the following aliases for Start-Sleep
:
Windows:
sleep
Ctrl+C
breaks out ofStart-Sleep
.Ctrl+C
does not break out of[Threading.Thread]::Sleep
. For more information, see Thread.Sleep Method.