111

PowerShellスクリプトとして単純なバッチファイルを作成しましたが、実行時にエラーが発生します。

それは私のパスのscriptsディレクトリにあります。これは私が得るエラーです:

このシステムではスクリプトの実行が無効になっているため、ロードできません。「get-helpabout-signing」をご覧ください。

ヘルプを調べましたが、役に立たないです。

4

10 に答える 10

108

これは、PowerShellのデフォルトのセキュリティレベルである可能性があり、(IIRC)は署名されたスクリプトのみを実行します。

これを入力してみてください:

set-executionpolicy remotesigned

これにより、PowerShellは、ローカル(つまり、ローカルドライブ上)の署名されていないスクリプトの実行を許可するようになります。

次に、スクリプトをもう一度実行してみてください。

于 2008-08-14T03:41:33.003 に答える
82

実行する必要がありますSet-ExecutionPolicy

Set-ExecutionPolicy Restricted <-- Will not allow any powershell scripts to run.  Only individual commands may be run.

Set-ExecutionPolicy AllSigned <-- Will allow signed powershell scripts to run.

Set-ExecutionPolicy RemoteSigned <-- Allows unsigned local script and signed remote powershell scripts to run.

Set-ExecutionPolicy Unrestricted <-- Will allow unsigned powershell scripts to run.  Warns before running downloaded scripts.

Set-ExecutionPolicy Bypass <-- Nothing is blocked and there are no warnings or prompts.
于 2013-11-14T10:15:31.470 に答える
29

使用する:

Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process

上記のコマンドを常に使用して、現在のセッションで PowerShell を実行できるようにします。

于 2013-04-22T07:16:58.470 に答える
21

次のように PowerShell を呼び出すことで、このエラーを回避できました。

powershell -executionpolicy bypass -File .\MYSCRIPT.ps1

つまり-executionpolicy bypass、スクリプトを呼び出す方法に を追加しました。

これは Windows 7 Service Pack 1 で機能しました。

[2017-06-26 を編集] Windows 10 や Windows 2012 R2 を含む他のシステムでこの手法を問題なく使用し続けています。

これが私が今使っているものです。これにより、スクリプトをクリックして誤って実行することがなくなります。スケジューラで実行すると、「スケジューラ」という引数が1つ追加され、プロンプトがバイパスされます。

これにより、最後にウィンドウも一時停止されるため、PowerShell の出力を確認できます。

if NOT "%1" == "scheduler" (
   @echo looks like you started the script by clicking on it.
   @echo press space to continue or control C to exit.
   pause
)

C:
cd \Scripts

powershell -executionpolicy bypass -File .\rundps.ps1

set psexitcode=%errorlevel%

if NOT "%1" == "scheduler" (
   @echo Powershell finished.  Press space to exit.
   pause
)

exit /b %psexitcode%
于 2015-11-30T20:13:10.583 に答える
6
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process

上記のコマンドは、次のエラーが発生した場合でも機能しました。

Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' is denied.
于 2014-02-21T00:23:53.893 に答える
5

.\また、スクリプト名の前に含める必要がある場合があることも知っておく価値があります。例えば:

.\scriptname.ps1
于 2008-08-14T03:47:47.857 に答える
1

このコマンドset-executionpolicy unrestrictedを使用すると、作成したスクリプトをログイン ユーザーとして実行できます。set-executionpolicy signedログアウトする前に、必ずコマンドを使用して実行ポリシー設定を署名付きに戻してください。

于 2012-07-18T20:23:26.260 に答える
0

Windows 10 の場合: myfile.ps1 のセキュリティ プロパティの変更をクリックし、myfile.ps1 のプロパティを右クリックして [アクセスを許可] を変更します。

于 2019-09-20T09:08:32.270 に答える