私は奇妙な状況にあり、問題を理解することができません。特定のパスのすべてのサブディレクトリのACLとAccessRulesを取得する必要があります。個別に行ってもエラーは発生しません
gci -recurse | Where-Object { $_.PSIsContainer } | Get-Acl | Format-List | Out-File C:\temp\permission.txt
gci -recurse | Where-Object { $_.PSIsContainer } | Get-Acl | foreach {$_.GetAccessRules($true, $true, [System.Security.Principal.NTAccount])} | Out-File C:\temp\permission1.txt -Append
ただし、これをforeachループで実行して、ファイルの生成方法をより適切に操作および処理したいと思います。スクリプトで実行しようとしていることは次のとおりです。
sl c:\test_folder
gci * -Recurse | Export-Csv c:\temp\dir.csv -Force
$pastas = gci -Recurse | where {$_.PsIsContainer}
if (Test-Path C:\temp\permission.txt)
{
ri c:\temp\permission.txt
}
foreach ($pasta in $pastas)
{
$pasta
Test-Path $pasta
$acl = get-acl $pasta
$acl | format-list | Out-File -FilePath c:\temp\permission1.txt -Append
$acl.GetAccessRules($true, $true, [System.Security.Principal.NTAccount]) | Out-File -FilePath c:\temp\permission1.txt -Append
}
変数foreach
のルートにあるフォルダーで直接処理している間、はを返します。ただし、最初のサブディレクトリでは、が返されますが、フォルダは存在します。get-aclで、PathNotFound例外が発生します。$pastas
Test-Path
true
Test-Path
false
Get-Acl : Não é possível localizar o caminho 'Exportacao' porque ele não existe.
Em C:\Temp\Script Get Info.ps1:12 caractere:17
+ $acl = get-acl <<<< $pasta
+ CategoryInfo : ObjectNotFound: (:) [Get-Acl], ItemNotFoundException
+ FullyQualifiedErrorId : GetAcl_PathNotFound_Exception,Microsoft.PowerShell.Commands.GetAclCommand
私は何が間違っているのですか?