REF:https://qiita.com/Targityen/items/3d2e0b5b0b7b04963750
現象:
c:\tmp.\test.ps1
... + .\test.ps1
+ ~~~~~~~~~~
+ CategoryInfo : セキュリティ エラー: (: ) []、PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
... + .\test.ps1
+ ~~~~~~~~~~
+ CategoryInfo : セキュリティ エラー: (: ) []、PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
原因:
PS C:\tmp\> get-executionPolicy
Restricted
実行ポリシー | 署名あり | 署名なし/ローカル | 署名なし/非ローカル | 説明 |
---|---|---|---|---|
Restricted | x | x | x | すべてのスクリプトの実行を制限 (初期設定) |
AllSigned | o | x | x | 署名のあるスクリプトのみ実行可能 |
RemoteSigned | o | o | x | ローカル上のスクリプトと非ローカル上の署名のあるスクリプトのみ実行可能 |
Unrestricted | o | o | △ | すべてのスクリプトが実行可能だが非ローカル上のスクリプトは実行時に許可が必要 |
Bypass | o | o | o | すべてのスクリプトが実行可能 |
対策:
1. ps1ファイルに個別指定
c:\tmp>PowerShell -ExecutionPolicy RemoteSigned .\test.ps1
2. ps1ファイルに共通指定
c:\tmp>PowerShell Set-ExecutionPolicy RemoteSigned
没有评论:
发表评论