指定時間後にSuspend

指定時間後にSuspend

指定した時間の後にWindowsをサスペンドするためのスクリプト。参照先は以下。

Suspend or hibernate from PowerShell
I am interested in using Windows PowerShell to suspend or hibernate a computer. How do you achieve this? I am already aware of the Stop-Computer and Restart-Computer cmdlets, which are included ou…
<#
.SYNOPSIS 
Suspend PC
.PARAMETER sleep
   specifies waiting seconds to suspend.
.DESCRIPTION
The followings are steps to suspend this PC.
1.Define the power state you wish to set, from the System.Windows.Forms.PowerState enumeration.
2.Define whether or not to force the power state
3.Define whether or not to disable wake capabilities
4.Set the power state
5.Execute
Refer from https://stackoverflow.com/questions/20713782/suspend-or-hibernate-from-powershell
#>
Param(
    [Int]$sleep = 0
)
Start-Sleep -s $sleep
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 
$PowerState = [System.Windows.Forms.PowerState]::Suspend;
$Force = $true;
$DisableWake = $false;
[System.Windows.Forms.Application]::SetSuspendState($PowerState, $Force, $DisableWake);

これで以下のコマンドで1時間後にスリープする。

.\suspend.ps1 -sleep 3600