2022年7月11日星期一

powershell PSSecurityException, FullyQualifiedErrorId : UnauthorizedAccess

REF:https://qiita.com/Targityen/items/3d2e0b5b0b7b04963750

現象:

c:\tmp.\test.ps1
... + .\test.ps1
+ ~~~~~~~~~~
+ CategoryInfo : セキュリティ エラー: (: ) []、PSSecurityException 
+ FullyQualifiedErrorId : UnauthorizedAccess 

原因:
PS C:\tmp\> get-executionPolicy
Restricted

実行ポリシー署名あり署名なし/ローカル署名なし/非ローカル説明
Restrictedxxxすべてのスクリプトの実行を制限 (初期設定)
AllSignedoxx署名のあるスクリプトのみ実行可能
RemoteSignedooxローカル上のスクリプトと非ローカル上の署名のあるスクリプトのみ実行可能
Unrestrictedooすべてのスクリプトが実行可能だが非ローカル上のスクリプトは実行時に許可が必要
Bypassoooすべてのスクリプトが実行可能

対策:
1. ps1ファイルに個別指定
c:\tmp>PowerShell -ExecutionPolicy RemoteSigned .\test.ps1


2. ps1ファイルに共通指定
c:\tmp>PowerShell Set-ExecutionPolicy RemoteSigned

没有评论: