LoginSignup
17
22

More than 5 years have passed since last update.

PowerShellメモ シャットダウン、再起動、スリープ

Posted at

概要

PowerShellでシャットダウン、再起動、スリープ(サスペンド)する方法。

コード

シャットダウン

強制オプション付き。

Stop-Computer -Force

再起動

強制オプション付き。

Restart-Computer -Force

スリープ

Suspend-Computerだとそのうち名前が被りそうなので違う関数名にした。

Add-Type -AssemblyName System.Windows.Forms

<#
.SYNOPSIS
    コンピューターをサスペンド
#>
function SleepPC
{
    $state = [System.Windows.Forms.PowerState]::Suspend
    [bool]$force = $true
    [bool]$disableWakeEvent = $false

    [System.Windows.Forms.Application]::SetSuspendState($state, $force, $disableWakeEvent)
}

動作確認した環境

  • PowerShell V5 (Windows 10)

参考サイト

Stop-Computer - MSDN
Restart-Computer - MSDN
Application.SetSuspendState メソッド - MSDN

17
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
22