Powershell

How to Use the “Start-Sleep” Command in PowerShell?

The “Start-Sleep” cmdlet is utilized in PowerShell to suspend or pause the activity of a console session or script for a specified time. Moreover, the stated cmdlet can also help wait for a specific operation to complete before pausing the activity. However, this cmdlet returns no output in the PowerShell console.

This tutorial will discuss the cmdlet “Start-Sleep” in detail.

How to Use the PowerShell “Start-Sleep” Command?

As described above, the cmdlet “Start-Sleep” is responsible for pausing or waiting for a specific cmdlet to be executed.

Let’s check out the below-given examples for a practical demonstration of the “Start-Sleep” command.

Example 1: Use the “Start-Sleep” Cmdlet to Pause the Execution

The below-given cmdlet will pause the execution of the script for a specified time:

Start-Sleep

 

Example 2: Use the “Start-Sleep” Cmdlet to Pause the Execution for Five Seconds

The following illustration will pause the execution of the specific command for a required time:

Start-Sleep -Seconds 5

 

In accordance with the above command:

  • First, specify the “Start-Sleep” cmdlet.
  • After that, specify the “-Seconds” parameter and assign the value of “5” seconds:

Example 3: Use the “Start-Sleep” Cmdlet to Wait for Five Seconds Before Execution of the Another Command

To add the interval of ten seconds between the execution of the two commands, use the below-stated cmdlet:

Start-Sleep -Seconds 5; Get-Date

 

In the above-provided code:

  • Initially, specify the “Start-Sleep” cmdlet, along with the “-Seconds” parameter having the value of “5” seconds.
  • After that, add the second cmdlet, such as “Get-Date” to be executed:

Example 4: Use the “Start-Sleep” Cmdlet to Add the Ten Seconds Interval Between Two Cmdlet Execution

In this demonstration, an interval of ten seconds will be added between the execution of two commands:

Get-Date; Start-Sleep -S 10; Get-Date

 

According to the above-given code:

  • First, add the “Get-Date” cmdlet.
  • Then write the “Start-Sleep” cmdlet, followed by the “-S” parameter having the value “10” seconds assigned to it.
  • Lastly, add another cmdlet to be executed:

That was all about the “Start-Sleep” cmdlet in PowerShell.

Conclusion

The “Start-Sleep” cmdlet in PowerShell is responsible for suspending an activity or pausing a session for a specified time. Moreover, it can add the specified time interval between the execution of the two cmdlets. This post has elaborated on the “Start-Sleep” cmdlet in detail.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.