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}

Example:
echo "hello"
Start-Sleep -s 1

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

pwd
echo "Sleeping for 5 seconds..."
Start-Sleep -s 5
Output:
PS C:\> echo "hello"
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

Path
----
C:\


PS C:\> echo "Sleeping for 5 seconds..."
Sleeping for 5 seconds...
PS C:\> Start-Sleep -s 5
PS C:\>
Advertisements
Try Out Code2care Dev Tools:

Advertisements



#Android #Java #Linux #Microsoft #Google #Python #MacOS #Notepad++ #Microsoft Teams #CSS #PHP #SharePoint #Html #Linux #C-Program #Bootstrap #jQuery #Sublime #Android-Studio #Facebook #Eclipse #WhatsApp #News #MySQL #Json #HowTos #JavaScript #FTP #S3


Advertisements


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Tutorials, Trouble-Shooting steps, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.
🎉 We are celebrating the 10th years of Code2care! Thank you for all your support! We hope we made a difference.
We strong support Gender Equality & Diversity.

We stand in solidarity with Ukraine - Make a donation to UNHCR - https://donate.unhcr.org/in/en-in/ukraine-emergency