Skip to content

Instantly share code, notes, and snippets.

@scichelli
Created November 27, 2012 02:14
Show Gist options
  • Save scichelli/4151973 to your computer and use it in GitHub Desktop.
Save scichelli/4151973 to your computer and use it in GitHub Desktop.
Show an alert and then set the computer to sleep
$WarningDuration = 5
$MessagePlural = ""
if ($WarningDuration -gt 1) { $MessagePlural = "s" }
[System.Media.SystemSounds]::Asterisk.play()
[void] [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[windows.forms.messagebox]::show(("Save your work. Sleep in {0} minute{1}." -f $WarningDuration, $MessagePlural))
Start-Sleep -Second ($WarningDuration * 60)
[System.Media.SystemSounds]::Beep.play()
Start-Sleep -Second 2
[System.Windows.Forms.Application]::SetSuspendState("Suspend", $false, $true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment