| サンプル集 |
|
■VC ■C# ■Java ■BorlandC ■LinuxC ■MS-DOS ■bash ■Excel VBA ■VBScript ■PHP ■HTML ■perl ■iPhone ■Android ■Lua ■WordPress ■PowerShell ■Python ■Flutter ■other |
| Linuxコマンド |
| 用語集 |
| debian メモ |
| apache2 メモ |
| MySQL メモ |
| Oracle メモ |
| HOME |
Get-ChildItemでディレクトリの内容を取得します。
◆環境| OS | Windows 10 Home 20H2 64bit OS x64 |
|---|
Get-ChildItemでディレクトリ情報を取得しforeachで要素を表示します。
| Get-ChildItemTest.ps1 | ||
|
実行したところエラーが出ました。
PS C:\work> .\Get-ChildItemTest.ps1
.\Get-ChildItemTest.ps1 : ファイル C:\work\Get-ChildItemTest.ps1 を読
み込めません。ファイル C:\work\Get-ChildItemTest.p
s1 はデジタル署名されていません。このスクリプトは現在のシステムでは実
行できません。スクリプトの実行および実行ポリシーの
設定の詳細については、「about_Execution_Policies」(https://go.microsoft.com/fwlink/?LinkID=135170) を参照してください。
発生場所 行:1 文字:1
+ .\Get-ChildItemTest.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : セキュリティ エラー: (: ) []、PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
.\Get-ChildItemTest.ps1 : ファイル C:\work\Get-ChildItemTest.ps1 を読
み込めません。ファイル C:\work\Get-ChildItemTest.ps1 はデジタル署名されていません。このスクリプトは現在のシステムでは実
行できません。スクリプトの実行および実行ポリシーの設定の詳細については、「about_Execution_Policies」(https://go.microsoft.com/fwlink/?LinkID=135170) を参照してください。
発生場所 行:1 文字:1
+ .\Get-ChildItemTest.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : セキュリティ エラー: (: ) []、PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
現在のポリシーをGet-ExecutionPolicyで確認します。
PS C:\work> Get-ExecutionPolicy -list
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine RemoteSigned
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine RemoteSigned
ProcessがUndefinedになっています。
Set-ExecutionPolicyでProcessのポリシーをBypassに変更します
PS C:\work> Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypas
s
実行ポリシーの変更
実行ポリシーは、信頼されていないスクリプトからの保護に役立ちます。実
行ポリシーを変更すると、about_Execution_Policies
のヘルプ トピック (https://go.microsoft.com/fwlink/?LinkID=135170)
で説明されているセキュリティ上の危険にさらされる可能性があります。実
行ポリシーを変更しますか?
[Y] はい(Y) [A] すべて続行(A) [N] いいえ(N) [L] すべて無視(L) [S
] 中断(S) [?] ヘルプ (既定値は "N"): Y
s実行ポリシーの変更
実行ポリシーは、信頼されていないスクリプトからの保護に役立ちます。実
行ポリシーを変更すると、about_Execution_Policiesのヘルプ トピック (https://go.microsoft.com/fwlink/?LinkID=135170)
で説明されているセキュリティ上の危険にさらされる可能性があります。実
行ポリシーを変更しますか?[Y] はい(Y) [A] すべて続行(A) [N] いいえ(N) [L] すべて無視(L) [S
] 中断(S) [?] ヘルプ (既定値は "N"): Yポリシーを確認してみます。
PS C:\work> Get-ExecutionPolicy -list
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Bypass
CurrentUser Undefined
LocalMachine RemoteSigned
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Bypass
CurrentUser Undefined
LocalMachine RemoteSigned
ProcessがBypassになりました。
再度実行してみます。
PS C:\work> .\Get-ChildItemTest.ps1
Get-ChildItemTest START
..\src
Get-ChildItemTest.ps1
Get-ChildItemTest END
Get-ChildItemTest START
..\src
Get-ChildItemTest.ps1
Get-ChildItemTest END
期待通りに動作しました。
Copyright (C) 2025 ymlib.com
