PowerShellスクリプトを簡単実行

More than 1 year has passed since last update.

PowerShellスクリプト(.ps1ファイル)の実行はちょっと手間。
一般的な実行方法は、

  1. Windows PowerShellを起動
  2. Set-ExecutionPolicyコマンドで実行ポリシーを変更
  3. ps1ファイルを実行
  4. Set-ExecutionPolicyコマンドで実行ポリシーを戻す

と少々面倒くさい。

バッチファイル(.batファイル)を使えば、
Windows PowerShellの起動も実行ポリシーの変更もすることなく
PowerShellスクリプトを実行できる。

powershell.bat
powershell -ExecutionPolicy RemoteSigned -File D:\temp\powershell.ps1
pause
powershell.ps1
Write-Host "PowerShell実行"

上記のようなバッチファイルを管理者として実行すればよい。

【補足】
- -ExecutionPolicyの設定は当該セッションのみで有効なので、設定を戻す必要なし。

【参考】
Windows PowerShell: PowerShell.exe
Windows PowerShell スクリプトを実行する

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away