我有一个脚本可以审核 NTFS 权限。
ForEach ($Folder in $Folders){
$ACLs = Get-ACL $Folder.FullName | % { $_.Access }
ForEach ($ACL in $ACLs){
$OutInfo = $Folder.Fullname + "," + $ACL.IdentityReference + "," + $ACL.AccessControlType + "," + $ACL.FileSystemRights + "," + $ACL.IsInherited + "," + $ACL.InheritanceFlags + "," + $ACL.PropagationFlags
Add-Content -Value $OutInfo -Path $outputCSV
}
}
但是,由于脚本作为用户的上下文运行,因此该帐户无权访问某些文件夹,因此在 powershell CLI 中吐出我们的错误,说访问被拒绝等。我该如何:
a). Hide it from the Powershell CLI
b). Redirect it to a notepad/txt file log so I still have the information.
+ $Folders = dir $pathToFolders -recurse | where {$_.psiscontainer -eq $true}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (F:\SEPM:String) [Get-ChildItem], UnauthorizedAccessException
+ FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
Get-ACL : Attempted to perform an unauthorized operation.
它不会使用以下方法将其写入文本文件吗?