更新时间:2023-01-29 19:41:36
在 Get-Acl
之前移动一个 ForEach-Object
,然后使用 DirectoryInfo
对象的路径和修改时间。在创建对象之前,我还要过滤继承的权限(先创建对象,然后再丢弃它们是浪费资源)。
Move one ForEach-Object
before the Get-Acl
, and use the DirectoryInfo
objects for path and modification time. I'd also filter for inherited permissions before creating the objects (creating objects first and throwing them away later is a waste of resources).
$root = 'C:\files'
$csv = 'C:\path\to\test_dump.csv'
Get-ChildItem $root -Recurse |
Where-Object { $_.PSIsContainer } |
ForEach-Object {
$dir = $_
Get-Acl $dir | Select-Object -Expand Access |
Where-Object { $_.IsInherited } |
ForEach-Object {
New-Object PSObject -Property @{
Folder = $dir.FullName
Access = $_.FileSystemRights
Control = $_.AccessControlType
User = $_.IdentityReference
Inheritance = $_.IsInherited
LastModified = $dir.LastWriteTime
}
}
} | Export-Csv $csv -Force
如果至少具有PowerShell v3,则可以使用 Get-ChildItem -Directory
而不是必须过滤 $ _。PSIsContainer
。
If you have at least PowerShell v3 you can use Get-ChildItem -Directory
instead of having to filter for $_.PSIsContainer
.