---
title: "Master Start-Sleep: Pause Scripts Efficiently"
description: "Learn to use start-sleep for pausing scripts, especially in while loops that execute code, for better control and efficiency."
canonical: "https://adamtheautomator.com/start-sleep/"
---

# Master Start-Sleep: Pause Scripts Efficiently

> Learn to use start-sleep for pausing scripts, especially in while loops that execute code, for better control and efficiency.

Source: https://adamtheautomator.com/start-sleep/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Master Start-Sleep: Pause Scripts Efficiently](https://adamtheautomator.com/wp-content/uploads/2019/06/5d238ae5c824b514689ea53b.jpg)

# Master Start-Sleep: Pause Scripts Efficiently

[![](https://secure.gravatar.com/avatar/d0b9d42e21e5622713f8b693aa5c0f9244d5f7dd200ed29b8398f52dee5de337?s=192&d=mm&r=g)Adam Bertram](https://adamtheautomator.com/author/adam-bertram/)17 June 20191 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[PowerShell](/tag/powershell/)

Table of Contents

*   [Start-Sleep Usage](#start-sleep-usage)
*   [Example Context](#example-context)

The PowerShell Start-Sleep cmdlet or the `sleep` alias is a simple cmdlet with a single purpose; to pause a script. When executed, in the PowerShell console, a script executed by the console or in the PowerShell ISE, the cmdlet pauses merely a script or module in the PowerShell session from running until the required time in seconds or milliseconds have elapsed.

This cmdlet is simple yet can be applied in a few different ways that will allow us scripters to greate well-written scripts.

## Start-Sleep Usage

Using the Start-Sleep cmdlet is extremely easy since, after all, it only has two parameters! Let’s say I want to pause my script because I’m waiting for some other environmental process to run. That process takes around 10 seconds, and I need to be sure that my script doesn’t keep running before that external event is done.

To pause the script for 10 seconds, I’d just use `Start-Sleep -Second 10`. If I want to get anal about things, I could also specify the time in milliseconds as `Start-Sleep -Milliseconds 10000.`

## Example Context

One of the most common uses of this Start-Sleep cmdlet is inside of a `while` loop. A `while` loop is a construct in PowerShell that executes code _while_ something else is happening. One of the best uses of a `while` loop is to wait for something else to happen. Rather than just guessing how long a process is going to take and running this cmdlet directly.

For example, perhaps you need to wait for a file to show up in a folder. Maybe that file is dropped there by some other software. Once the file is in the folder, you need to run some code against it. This example is an excellent example of using a `while` loop and `Start-Sleep`.

In the example below, my code is waiting for the `C:\File.txt` file to show up. If this were in a script, it would pause the script until this event happened. _Technically_, we don’t need `Start-Sleep` to do this, but if not used, this code could cripple your computer. The speed at which it could continually check for this file would be up to PowerShell!

We don’t need to check this file every .0455ms. Instead, we should slow that check down and only perform the test every five seconds. Slowing a while loop down is an excellent use of the `Start-Sleep` command.

```powershell
$filePath = 'C:\File.txt'
while (-not (Test-Path -Path $filePath)) {
    ## Wait a specific interval
    Start-Sleep -Seconds 5
}
```

For an example of using this cmdlet with a nice progress bar, [check this out](https://gist.github.com/ctigeek/bd637eeaeeb71c5b17f4).

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fstart-sleep%2F&text=Master%20Start-Sleep%3A%20Pause%20Scripts%20Efficiently)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fstart-sleep%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fstart-sleep%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/06/26995-troubleshoot-dns-issues-powershell-codex.webp)

### [Troubleshoot DNS Issues with PowerShell](/troubleshoot-dns-issues-powershell/)

Troubleshoot DNS issues with PowerShell by testing name resolution, DNS client settings, cache entries, and network connectivity in a repeatable workflow.

![](https://adamtheautomator.com/wp-content/uploads/2025/10/image_2025-10-24_095322075.png)

### [Migrating from PowerShell 6 to 7.5: Breaking Changes/New Features](/migrating-powershell-6-to-7-5/)

Migrate from PowerShell Core 6 to 7.5: breaking changes, features, and testing tips.

![](https://adamtheautomator.com/wp-content/uploads/2025/06/featured-image-6.png)

### [How to Add Timeouts to Pester Tests with PowerShell Runspaces](/pester-test-timeout-runspaces/)

Prevent Pester tests from hanging indefinitely using PowerShell runspaces. Learn to handle variable scoping, module loading, TestDrive access, and stream capture challenges with timeout protection.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
