如何获得某种格式的 FileSystemRights?
How do I get FileSystemRights in a certain format?
我写了一个小脚本来为我提供特定路径及其所有子目录的访问 ACL,并将其放在 .txt 中,但我需要它以另一种格式创建一个更容易查看和访问的数据库。
部分输出如下所示:
Fullname S FileSystemRights S AccessControlType
---------- ------------------ ------------------
C:\temp ; ReadAndExecute, Synchronize ; Allow;
所以我需要的输出看起来像这样:
Fullname S FileSystemRights S AccessControlType
---------- ------------------ ------------------
C:\temp ; ReadAndExecute ; Allow;
C:\temp ; Synchronize ; Allow;
如您所见,我需要单独的行中的单独权限,而不是堆叠在一起。
到目前为止我所做的看起来如下,也许它有帮助(我遗漏了不重要的东西):
(Get-Acl $TestPath).Access |
Format-Table -AutoSize -HideTableHeaders @{L="Fullname";E={$TestPath}},
@{L="S";E={";"}}, FileSystemRights,
@{L="S";E={";"}}, AccessControlType,
@{L="S";E={";"}}, IdentityReference,
@{L="S";E={";"}}, IsInherited,
@{L="S";E={";"}}, InheritanceFlags,
@{L="S";E={";"}}, PropagationFlags |
Out-File $Out -Append -Width 500
function RecDirs {
$d = $Args[0]
$AktRec++
$dirs = dir $d | where {$_.PsIsContainer}
if ($AktRec -lt 3) {
foreach($di in $dirs) {
if ($di.FullName -ne $null) {
(Get-Acl $di.Fullname).Access |
Format-Table -AutoSize -HideTableHeaders @{L="Fullname";E={$di.FullName}},
@{L="S";E={";"}}, FileSystemRights,
@{L="S";E={";"}}, AccessControlType,
@{L="S";E={";"}}, IdentityReference,
@{L="S";E={";"}}, IsInherited,
@{L="S";E={";"}}, InheritanceFlags,
@{L="S";E={";"}}, PropagationFlags |
Out-File $Out -Append -Width 500
}
RecDirs($di.Fullname)
}
}
}
RecDirs($TestPath)
用逗号分隔FileSystemRights
属性,每个元素输出一行。你肯定想要 Export-Csv
来编写输出文件。
(Get-Acl $di.Fullname).Access | ForEach-Object {
foreach ($val in ($_.FileSystemRights -split ', ')) {
$_ | Select-Object @{n='Fullname';e={$di.FullName}},
@{n='FileSystemRights';e={$val}}, AccessControlType,
IdentityReference, IsInherited, InheritanceFlags,
PropagationFlags
}
} | Export-Csv $Out -NoType -Append
我写了一个小脚本来为我提供特定路径及其所有子目录的访问 ACL,并将其放在 .txt 中,但我需要它以另一种格式创建一个更容易查看和访问的数据库。
部分输出如下所示:
Fullname S FileSystemRights S AccessControlType ---------- ------------------ ------------------ C:\temp ; ReadAndExecute, Synchronize ; Allow;
所以我需要的输出看起来像这样:
Fullname S FileSystemRights S AccessControlType ---------- ------------------ ------------------ C:\temp ; ReadAndExecute ; Allow; C:\temp ; Synchronize ; Allow;
如您所见,我需要单独的行中的单独权限,而不是堆叠在一起。
到目前为止我所做的看起来如下,也许它有帮助(我遗漏了不重要的东西):
(Get-Acl $TestPath).Access |
Format-Table -AutoSize -HideTableHeaders @{L="Fullname";E={$TestPath}},
@{L="S";E={";"}}, FileSystemRights,
@{L="S";E={";"}}, AccessControlType,
@{L="S";E={";"}}, IdentityReference,
@{L="S";E={";"}}, IsInherited,
@{L="S";E={";"}}, InheritanceFlags,
@{L="S";E={";"}}, PropagationFlags |
Out-File $Out -Append -Width 500
function RecDirs {
$d = $Args[0]
$AktRec++
$dirs = dir $d | where {$_.PsIsContainer}
if ($AktRec -lt 3) {
foreach($di in $dirs) {
if ($di.FullName -ne $null) {
(Get-Acl $di.Fullname).Access |
Format-Table -AutoSize -HideTableHeaders @{L="Fullname";E={$di.FullName}},
@{L="S";E={";"}}, FileSystemRights,
@{L="S";E={";"}}, AccessControlType,
@{L="S";E={";"}}, IdentityReference,
@{L="S";E={";"}}, IsInherited,
@{L="S";E={";"}}, InheritanceFlags,
@{L="S";E={";"}}, PropagationFlags |
Out-File $Out -Append -Width 500
}
RecDirs($di.Fullname)
}
}
}
RecDirs($TestPath)
用逗号分隔FileSystemRights
属性,每个元素输出一行。你肯定想要 Export-Csv
来编写输出文件。
(Get-Acl $di.Fullname).Access | ForEach-Object {
foreach ($val in ($_.FileSystemRights -split ', ')) {
$_ | Select-Object @{n='Fullname';e={$di.FullName}},
@{n='FileSystemRights';e={$val}}, AccessControlType,
IdentityReference, IsInherited, InheritanceFlags,
PropagationFlags
}
} | Export-Csv $Out -NoType -Append