Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Show an alert and then set the computer to sleep
$WarningDuration = 5
$MessagePlural = ""
if ($WarningDuration -gt 1) { $MessagePlural = "s" }
[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)
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