约 807 字

约 4 分钟

#PowerShell 的 Start-Sleep 命令

Start-Sleep [-Seconds] <Double>
Start-Sleep -Milliseconds <Int32>
Start-Sleep -Duration <TimeSpan>

功能

暂停当前脚本或会话一段时间,随后继续执行。可以用 Ctrl+C 中断等待。

类型

Cmdlet,属于 Microsoft.PowerShell.Utility。

参数

  • -Seconds 以秒为单位,支持小数。
  • -Milliseconds 以毫秒为单位。
  • -Duration 接收 TimeSpan,从 PowerShell 7.3 起可用。

#示例

在两次输出之间暂停

Write-Output '开始'
Start-Sleep -Milliseconds 300
Write-Output '完成'
开始
完成

第二行在约 300 毫秒后显示。

#推荐阅读

更新: 2026/11/27

作者: planc

创建: 2026/11/27