LoginSignup
1
0

More than 1 year has passed since last update.

powershellでrebootコマンドから再起動できるようにする

Posted at

この記事について

WindowsでPowerShellを使っている際、Linuxのように reboot でPCの再起動をできるようにした際のメモです。

動作確認に利用した環境

Windows 10 Pro
PowerShell 7.2.0

PowerShellでの再起動コマンド

上記に書かれているように、以下コマンドのいずれかで再起動できます。

Restart-Computer
Restart-Computer -Force

今回は Force オプションを付けたものにエイリアスを設定していきます。

rebootのエイリアス設定

設定を永続化させるためにPowerShellのプロファイルに記入します。
プロファイルの場所については、こちらに詳しく記述されています。

プロファイルが存在しない場合は、PowerShellで以下コマンドで実行ポリシーの変更と作成を行います。

Set-ExecutionPolicy RemoteSigned -Force
New-Item type file force $profile

次に、プロファイルの編集を行います。

notepad $profile

メモ帳が開いたら、以下の内容を記述します。

# reboot
function reboot() {
  Restart-Computer -Force
}

PowerShellを再起動すると、 reboot でPCの再起動ができるようになります。

参考

1
0
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
1
0