PowerShell Start-Sleep Command: Syntax, Examples

-

|

Introduction

Powershell Sleep (Start-Sleep) Cmdlet is a very useful scripting tool. There may be instances when you want to delay your script for some time before you proceed to the next line (see my second example). This is where you need Powershell Sleep.

In this short guide, you will learn the syntax, parameters and examples of Powershell Sleep (Start-Sleep) Cmdlet.

Powershell Sleep: Syntax of Start-Sleep Cmdlet

Here is the syntax of Start-Sleep Cmdlet:

Start-Sleep -Milliseconds <Int32> 

Or

Start-Sleep -Seconds <Int32> 

This cmdlet has just two parameters: -Milliseconds – use it to specify the time (Int32) in milliseconds to suspend the activity of your script before it proceeds. You can also use the -Seconds parameter to specify the time in seconds.

The alias of Start-Sleep is Sleep. So you can use Sleep in place of Start-Sleep. Also the two parameters discussed earlier, -Milliseconds and -Seconds has aliases m and s respectively.

Powershell Sleep Examples

This section provides some examples of how to use Powershell Sleep (Start-Sleep) Cmdlet.

Powershell Sleep Example 1

To delay your script for 30000 Milliseconds (30 seconds), use any of the commands below:

Start-Sleep -Milliseconds 30000
Start-Sleep -m 30000 

When you run this command in PowerShell, the cursor will not return until after 30 seconds. See the image below. Notice that the cursor is not blinking. When the “sleep” completes, the command prompt will return. See the second image below.

Powershell Sleep Example 1

Powershell Sleep Example 2

I used the method in this example in a script I wrote some years ago. The script in question enabled office 365 mailbox when an on-site Active Directory user is created. This was a fully automated process!

Note that the commands described below are simplified versions of the actual command in the script I am describing. For privacy reasons I cannot share the actual script.

The process of enabling an office 365 mailbox involves a series of commands. The part of the script I used start-sleep is after I ran the commands below:

Set-CASMailbox

and

Set-MsolUserLicense

These two commands prepared the user’s account before the user’s office 365 mailbox is enabled. The above command needs some time to prepare the user’s account before the next command is executed.

To give the commands time to complete and the user account get ready, I added the command below before the next one:

Start-Sleep -Seconds 180

This forced the script to delay 180 seconds (3 minutes) before the next line of command ran. The portion of the script with the sleep command is shown below:

Once the delay completed, the script ran the command below:

Set-Mailbox
Describing this here may not seem like a big deal but when I was creating the script in question, it kept failing until I introduced the delay. So, sometimes PowerShell sleep can make or break your script!

Conclusion

I hope this short guide have simplified how to use Start-Sleep cmdlet for you. As I mentioned in my second example, this may be a very simple command but sometimes this simple knowledge can literally make you a star!

If you have any question or comment use the “Leave a Reply” form found at the end of this page. Alternatively, you could share your experience with Start-Sleep command.

Other Helpful Guides

Additional Resources and References

  • Was this post Helpful?
  • YesNo

LEAVE A REPLY

Please enter your comment!
Please enter your name here

ADVERTISEMENTS

FEATURED POSTS

How to Share Amazon Wish List

How to Share Amazon Wish List

This Itechguide teaches you how to share Amazon Wish List. The guide covers steps to share Amazon Wish List from a PC...
How to Pay with PayPal on Amazon

How to Pay with PayPal on Amazon

This Itechguide teaches you how to pay with PayPal on amazon. The guide covers 2 options to pay with PayPal on amazon....
How to Export Contacts from Outlook

How to Export Contacts from Outlook

This Itechguide teaches you how to export contacts from Outlook. The guide covers steps to export contacts from Outlook (Windows 10) or...
Best 90s Movies on Netflix

The 10 Best 90s Movies on Netflix

This Itechguide reviews the 10 best 90s movies on Netflix. The movies are listed in reverse order – with the 10th movie...
How to Clear Search History on Instagram

How to Clear Search History on Instagram

This Itechguide teaches you how to clear search history on Instagram. The guide covers steps to clear search history on Instagram from...

AMAZON DEALS

TRENDING POSTS

Remote Desktop Connection

Remote Desktop Connection an Internal Error Has Occurred [Fixed]

Introduction I recently received the error message "Remote Desktop Connection an Internal Error Has Occurred". It was strange because...

Find My Samsung: Register and Use Samsung Find my Mobile

Introduction Ever wondered how you could find your Samsung phone if you lost it? Find my Samsung or Samsung...
What is the Difference Between PowerShell and CMD?

Windows Powershell vs CMD: Differences and Similarities

Introduction This short guide compares Windows PowerShell vs CMD (Windows command prompt). I will cover the history and nature...
Spotify No Longer Supports this Version of Microsoft Edge

Spotify No Longer Supports this Version of Microsoft Edge [Fixed]

Introduction When you open Spotify web player on Microsoft Edge, you may receive the error message "Spotify No Longer...
Windows 10 Won't Boot

Windows 10 Won’t Boot With Black Screen? 3 Ways to Fix It

Why Won't Windows 10 Boot Up? If your Windows 10 stops with a black screen, the first question in...

ADVERTISEMENTS

BEST OF ITECHGUIDES

How to Uninstall Dropbox

How to Uninstall Dropbox

This Itechguide teaches you how to uninstall Dropbox. The guide covers steps to uninstall Dropbox from Windows 10, an Android phone and...
How to Delete Dropbox Account

How to Delete Dropbox Account

This Itechguide teaches you how to delete Dropbox account. If you Delete Dropbox account, your data is gone forever!
How to Change Language in Google Chrome

How to Change Language in Google Chrome

This Itechguide teaches you how to change language in Google Chrome. The guide covers steps to change language in Google Chrome in...
How to Add Borders in Google Docs

How to Add Borders in Google Docs (2 Methods)

This guide is a demo of how to add borders in Google Docs. As at the time of writing this guide Google...
How to Delete Instagram Messages

How to Delete Instagram Messages

This Itechguide teaches you how to delete Instagram messages. The guide covers two options to delete Instagram messages from the App:

RECENT POSTS

How to Search for a Word in Google Docs

How to Search for a Word in Google Docs

This Itechguide teaches you how to search for a word in Google Docs. The guide covers steps to search for a word...
How to Create a Folder in Google Docs

How to Create a Folder in Google Docs

This Itechguide teaches you how to create a folder in Google Docs. The guide covers steps to create a folder in Google...
How to Check Amazon Gift Card Balance

How to Check Amazon Gift Card Balance

This Itechguide teaches you how to check Amazon gift card balance. The guide covers steps to check Amazon gift card balance from...
How to Remove Google Account from Phone

How to Remove Google Account from Phone

This Itechguide teaches you how to remove Google Account from phone. The guide covers steps to remove Google Account from Android or...
How to Watch Instagram Live on PC

How to Watch Instagram Live on PC

This Itechguide teaches you how to watch Instagram live on PC. The guide covers 2 steps to watch Instagram live on PC....

AMAZON DEALS

MUST READ

How to Logout of Pinterest

How to Logout of Pinterest

This Itechguide teaches you how to logout of Pinterest. The guide covers steps to logout of Pinterest from the Apps for Android,...
network discovery keeps turning off server 2016

How to Fix Network Discovery If it Keeps Turning Off in Server 2016

Does network discovery keep turning off in your Windows server 2016? It is likely that one of its dependent services is not...
How to Fix "We Can't Activate Windows on this Device"

How to Fix “We Can’t Activate Windows on this Device”

Introduction Normally should be able to activate Windows from the Activate Windows settings page. Unfortunately, in some instances when...
powershell get-content foreach

How to Use Powershell Get-Content and ForEach With Examples

You can combine Powershell Get-Content and ForEach Loop in so many Windows automation tasks. Here is how it...
How to Convert PowerPoint to Google Slides

How to Convert PowerPoint to Google Slides

This Itechguide teaches you how to convert PowerPoint to Google Slides. The guide covers 2 methods to convert PowerPoint to Google Slides:

AMAZON DEALS

By using this website you agree to accept our Privacy Policy and Terms & Conditions