LoginSignup
4
5

More than 5 years have passed since last update.

PowerShellスクリプトをWindowsバッチ経由で起動する

Last updated at Posted at 2016-06-10

Windows PowerShellはデフォルト状態ではそのままps1のファイルを叩いても権限的に怒られて動作しない。常に実行するような環境であれば Set-ExecutionPolicy RemoteSigned などを実行する必要がある。

が、ちょろっと実行させたい場合にイチイチそれをやる(またはやらせる)のかと言われると説明が面倒になるし、永続的にその設定でよいのかという議論が出たりする場合もある。というかそもそも安易に管理者権限で~はどうなの。という話もある。
PowerShellのExecutionPolicyのスコープとかについて詳しく

そこで sample.ps1 というごじゃごじゃするPowerShellを実行する場合、同じディレクトリに同じ名前のバッチファイル

sample.bat
@powershell -ExecutionPolicy RemoteSigned -File %~n0.ps1 %*

を配布することで「batの方を叩いて」程度の指示で話が済むようになる(はず)。

4
5
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
4
5