Skip to content

Instantly share code, notes, and snippets.

@mahdilamb
Created June 10, 2024 17:04
Show Gist options
  • Select an option

  • Save mahdilamb/e7ce15baa3e9d9f9a3ce77266badb1a8 to your computer and use it in GitHub Desktop.

Select an option

Save mahdilamb/e7ce15baa3e9d9f9a3ce77266badb1a8 to your computer and use it in GitHub Desktop.
Hibernate the computer after a number of seconds. Format: `mm:ss`
param($DURATION)
$_POS = $DURATION.IndexOf(":")
$MINS = $DURATION.SubString(0, $_POS)
$SECS = $DURATION.SubString($_POS + 1, $DURATION.Length - [Int64]$_POS - 1)
$TOTAL_SECS = (([Int64]$MINS) * 60) + $SECS
$REMAINING_SECS = $TOTAL_SECS
while ($REMAINING_SECS -gt 0) {
Write-Host -NoNewLine "`rSleeping after $REMAINING_SECS seconds"
Start-Sleep -s 1
$REMAINING_SECS--
}
Write-Host ""
Write-Host "Done"
shutdown /h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment