対策
次のコマンドを実行します。
> Set-ExecutionPolicy Unrestricted -Scope CurrentUser
または
> Set-ExecutionPolicy Bypass -Scope CurrentUser
解説
PowerShellでスクリプトを実行すると、次のようなエラーになることがあります。
> nodist -v
nodist : このシステムではスクリプトの実行が無効になっているため、ファイル C:\Program Files (x86)\Nodist\bin\nodist.ps1
を読み込むことができません。詳細については、「about_Execution_Policies」(https://go.microsoft.com/fwlink/?LinkID=135170
) を参照してください。
発生場所 行:1 文字:1
+ nodist -v
+ ~~~~~~
+ CategoryInfo : セキュリティ エラー: (: ) []、PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
このエラーが発生する理由は、PowerShellの実行ポリシーにあります。
既定の実行ポリシーは”Restricted”で、これは制限の厳しいポリシーです。
ポリシーには次のものがあります。
- Restricted
- AllSigned
- RemoteSigned
- Unrestricted
- Bypass
- Undefined
各ポリシーの詳細は「about_Execution_Policies」を御覧ください。
現在のポリシーは次のコマンドで確認できます。
> Get-ExecutionPolicy
Restricted
実行ポリシーを変更するには、次のコマンドを実行します。
> Set-ExecutionPolicy 設定するポリシー -Scope CurrentUser
例えば、ポリシーをBypassに変更するときは次のコマンドを実行します。
> Set-ExecutionPolicy Bypass -Scope CurrentUser