PowerShell tutorial – exploring Start-Sleep CMDLET
Hi All,
Greetings for the day!!! Continuing the PowerShell tutorial
Today exploring one of the important CMDLET – Start-Sleep
Details / Use Case
- In one of the my application I was executing PowerShell script against SharePoint online
- PowerShell script was containing CMDLETs from SharePoint online module and looping through site collections
- Suddenly script started throwing and 429 error – Too Many Requests
- This means we are getting throttled in SharePoint online
- So the CMDLET Start-Sleep came to rescue 🙂
SharePoint Online uses throttling to maintain optimal performance and reliability of the SharePoint Online service. Throttling limits the number of API calls or operations within a time window to prevent overuse of resources
SYNTAX
Start-Sleep -Seconds <int>
Start-Sleep -Milliseconds <int>
- The
Start-Sleep
cmdlet suspends the activity in a script or session for the specified period of time - We can use it for many tasks, such as waiting for an operation to complete or pausing before repeating an operation
- In my PowerShell script I used this CMDLET – Start-Sleep in between SharePoint online CMDLETs and 429 error resolved
Demo
- Example 1 – Demonstrating pause of 2 seconds in between two CMDLETs
#getting current time
$currentTime = Get-Date -DisplayHint Time
Write-Host "Current time is - " $currentTime
Write-Host
Write-Host lets wait for 2 seconds
Write-Host
#pausing for 2 seconds
Start-Sleep -Seconds 2
#getting time after 2 seconds
$timeAfter2Secs = Get-Date -DisplayHint Time
Write-Host "After waiting 2 secs time is - " $timeAfter2Secs
Output :
Current time is - 9/2/2023 11:35:34 PM
lets wait for 2 seconds
After waiting 2 secs time is - 9/2/2023 11:35:36 PM
REFERENCES
Thanks for reading! If you think this is useful, kindly please like and share! HAVE a FANTASTIC LEARNING ! LIFE IS BEAUTIFUL 🙂
You must log in to post a comment.