How to add sleep in Powershell Script

To add sleep between statements or commands in Windows Powershell, you can make use of Start-Sleep -s {int}

echo "hello"
Start-Sleep -s 1

echo "Sleeping for 10 seconds..."
Start-Sleep -s 10

echo "Sleeping for 5 seconds..."
Start-Sleep -s 5
PS C:\> echo "hello"
PS C:\> Start-Sleep -s 1
PS C:\> ls

    Directory: C:\

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       11/14/2018   6:56 AM                EFI
d-----        5/13/2020   5:58 PM                PerfLogs
d-r---       11/14/2018   4:10 PM                Program Files
d-----        1/26/2022  11:16 AM                Program Files (x86)
d-r---        1/23/2022  11:37 PM                Users
d-----        1/23/2022  11:37 PM                Windows

PS C:\> echo "Sleeping for 10 seconds..."
Sleeping for 10 seconds...
PS C:\> Start-Sleep -s 10
PS C:\> pwd


PS C:\> echo "Sleeping for 5 seconds..."
Sleeping for 5 seconds...
PS C:\> Start-Sleep -s 5
PS C:\>

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail:

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap