Skip to content

Instantly share code, notes, and snippets.

@nanoDBA
Created September 6, 2024 20:16
Show Gist options
  • Save nanoDBA/4a25452c78d2127f96e1a8da7bb3785b to your computer and use it in GitHub Desktop.
Save nanoDBA/4a25452c78d2127f96e1a8da7bb3785b to your computer and use it in GitHub Desktop.
Sleep 5 hours in console/script
# Store TimeSpan object in variable $timespan
$timespan = New-TimeSpan -Start (Get-Date) -End (Get-Date).AddHours(5) #(Get-Date).AddDays(1).Date.AddHours(5) #careful with this - syntax is weird
# Print a message to the console in magenta color indicating the time the script will resume execution
Write-Host -ForegroundColor magenta "Sleeping until $((Get-date).AddSeconds($timespan.TotalSeconds)) ..."
# Pause the execution of the script for a number of seconds equal to the total seconds of the $timespan
Start-Sleep -Seconds $timespan.TotalSeconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment