Advertisements

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.
Advertisements


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


LEAVE A REPLY

Please enter your comment!
Please enter your name here

LATEST DEALS

Exclusive Student Offer_Save 10% on selected Surface devices

FEATURED POSTS

How to Change Administrator Name in Windows 10 (4 Methods)

How to Change Administrator Name in Windows 10

Introduction This guide demos how to change administrator name in Windows 10. There could be...
How to Setup WhatsApp Auto Reply in an Android Phone

How to Setup WhatsApp Auto Reply in an Android Phone

Introduction This guide demos how to setup Whatsapp auto reply in an Android phone. Steps...
How to Set Out of Office Auto Reply in Outlook, Outlook.com and Gmail

How to Set Out of Office Auto Reply in Outlook, Outlook.com and Gmail

Introduction This guide demos how to set out of office auto reply in Outlook, Outlook.com and Gmail.
How to Take Ownership of Folder in Windows 10

How to Take Ownership of Folder in Windows 10 (2 Methods)

Introduction This guide demos 2 methods to take ownership of folder in Windows 10. Options to...
How to Install Windows Server 2019 from USB

How to Install Windows Server 2019 from USB

Introduction This guide demos how to install Windows Server 2019 from USB. Steps to Install...

ADVERTISEMENTS

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

BEST OF ITECHGUIDES

How to Install and Configure WSUS in Windows Server 2019

How to Install and Configure WSUS in Windows Server 2019

Introduction This guide demos how to install and configure WSUS in Server 2019. Steps to Install...

How to Fix DISM Error 87 in Windows Server 2016 and Windows 10

Introduction DISM Error 87 in Windows Server 2016 can be cause by any of the following:
C:\G-Drive\Work Tools\Products Portal\1. New Business\2. Content Sites\1. iTechGuides.com\Posts\1. HOW TO\Microsoft\MS Office\Microsoft Word\how to add more rows to a table in word

How to Add More Rows to a Table in Word and Google Docs

Introduction This guide demos how to add more rows to a table in Word. It also has a...
Latest Windows 10 Update

How to Install Latest Windows 10 Update (May 2019 Update 1903)

Introduction The latest Windows 10 update is 1903. It was released May 2019. Microsoft strongly recommend updating to the...
How to Change Windows 10 Power Settings

How to Change Windows 10 Power Settings (3 Methods)

Introduction This guide demos how to change Windows 10 power settings. Options to Change Windows 10...

RECENT POSTS

C:\G-Drive\Work Tools\Products Portal\1. New Business\2. Content Sites\1. iTechGuides.com\Posts\1. HOW TO\Microsoft\MS Office\Microsoft Word\how to add more rows to a table in word

How to Add More Rows to a Table in Word and Google Docs

Introduction This guide demos how to add more rows to a table in Word. It also has a...
How to Create a Bar Chart in Excel and Google Sheets

How to Create a Bar Chart in Excel and Google Sheets

Introduction This guide demos how to create a bar chart in Excel and Google Sheets. A bar chart is...
How to Change Administrator Name in Windows 10 (4 Methods)

How to Change Administrator Name in Windows 10

Introduction This guide demos how to change administrator name in Windows 10. There could be...
How to Create a Pie Chart in Excel and Google Sheets

How to Create a Pie Chart in Excel and Google Sheets

Introduction This guide demos how to create a pie chart in Excel and Google Sheets. A pie chart is...

iTechGuides’ Top 10 Online Games

The gaming world is getting bigger day by day. Many people are getting engaged to play online games worldwide.

How to Open Local Security Policy in Windows 10 (5 Methods)

Introduction This guide demos how to open local security policy in Windows 10. Options to...

How to Change Network from Public to Private in Windows 10

Introduction This guide demos 2 methods to change network from public to private in Windows 10.
How to Disable Touchpad in Windows 10 for Dell or HP Laptop

How to Disable Touchpad in Windows 10 for Dell or HP Laptop

Introduction This guide demos how to Disable Touchpad in Windows 10 for a Dell or HP laptop.

How to Change Account Picture in Windows 10 (2 Methods)

Introduction This guide demos 2 methods to change account picture in Windows 10. Windows 10...
How to Create Xbox Live Account

How to Create Xbox Live Account (2 Methods)

Introduction This guide demos 2 methods to create Xbox Live account. Options to Create Xbox...

ADVERTISEMENTS

MUST READ

How to Find MAC Address in Windows 10 (4 Methods)

How to Find MAC Address in Windows 10 (4 Methods)

Introduction This guide demos 4 ways you can find MAC Address in Windows 10. Options...
Sort Gmail by Size

How to Sort Gmail by Size Using Gmail Search

Introduction If you are running out of space, you may want to sort Gmail by size so you can...
Windows defender blocked by Group Policy

Windows Defender Blocked by Group Policy [Fixed]

Introduction If you receive the error message Windows Defender is blocked by group policy, your computer may have been...
how to login to spotify without facebook

How to Login to Spotify Without Facebook

This guide shows you how to login to spotify without Facebook if you are creating a new Spotify account or if you...
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...

LATEST DEALS

Exclusive Student Offer_Save 10% on selected Surface devices

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