Memo
Windows 8のPowershellの実行許可を与える方法
そのままではエラーになります
1 2 3 4 5 6 7 8 |
PS C:\work> .\test.ps1 .\test.ps1 : このシステムではスクリプトの実行が無効になっているため、ファイル C:\work\test.ps1 を読み込むことができませ ん。詳細については、「about_Execution_Policies」(http://go.microsoft.com/fwlink/?LinkID=135170) を参照してください。 発生場所 行:1 文字:1 + .\test.ps1 + ~~~~~~~~~~ + CategoryInfo : セキュリティ エラー: (: ) []、PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess |
Windows PowerShell スクリプトを実行する
http://technet.microsoft.com/ja-jp/scriptcenter/powershell_owner05.aspx
about_Execution_Policies
http://technet.microsoft.com/ja-JP/library/hh847748.aspx
標準ではスクリプトは実行できない(Restricted)設定です。
しかしPowershellの利用を推奨しているのにそのままでは実行できないとは…
1 2 |
PS C:\work> Get-ExecutionPolicy Restricted |
実行許可をRemoteSignedに変更します
これはネットワーク上のスクリプトなどはデジタル署名が必要で、ローカルでの実行はデジタル署名が無くても実行できるようになります
1 2 3 4 5 6 7 8 9 10 11 12 13 |
PS C:\work> Set-ExecutionPolicy RemoteSigned 実行ポリシーの変更 実行ポリシーは、信頼されていないスクリプトからの保護に役立ちます。実行ポリシ ーを変更すると、about_Execution_Policies のヘルプ トピック (http://go.microsoft.com/fwlink/?LinkID=135170) で説明されているセキュリティ上の危険にさらされる可能性があります。実行ポリシ ーを変更しますか? [Y] はい(Y) [N] いいえ(N) [S] 中断(S) [?] ヘルプ (既定値は "Y"): Y PS C:\work> .\test.ps1 PowerShellの実行テスト PS C:\work> |
Powershell バージョン確認
http://gallery.technet.microsoft.com/scriptcenter/6aed190f-d9f1-422d-8b43-3d0ac072c267/
1 2 3 4 5 6 7 8 9 10 |
PS C:\work> Get-host Name : ConsoleHost Version : 3.0 InstanceId : 131f219c-1b43-49d4-9fa4-75c9a2812087 UI : System.Management.Automation.Internal.Host.InternalHostUserInterface CurrentCulture : ja-JP CurrentUICulture : ja-JP PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy IsRunspacePushed : False Runspace : System.Management.Automation.Runspaces.LocalRunspace |