LoginSignup
1
2

More than 3 years have passed since last update.

コマンドプロンプトからPowershellスクリプトを起動する

Last updated at Posted at 2019-05-21

batファイルからPowershellを管理者権限で外部スクリプトを呼び出したいということで備忘録として残します。
すでにPowershellをRestricted以外の動作モードの場合は他のページのやり方でうまくいくのですが、一度もPowershellを起動した環境がない場合の苦肉の策になります。

環境

Windows10 バージョン1803 (17134.765)

以下のコマンドをDOSプロンプトやバッチの中で実行する

一度もPowershellを起動していないPC等で、ダルクリックでPowershellスクリプトを実行したいときに有用かと思います。


powershell -NoProfile -ExecutionPolicy RemoteSigned -Command "Start-Process powershell.exe -ArgumentList \"-ExecutionPolicy RemoteSigned\",\"hello.ps1\" -Verb runas"

-ArgumentListの書き方はいろいろあるようだが、string型の配列らしい。
実行するスクリプトへはパスを通すかフルパスで指定が必要です

参考

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