我不是powershell专家,但是我写了一些较小的脚本。现在正在处理一个脚本,该脚本向我返回了文件夹及其子项的ACL。
当我只运行get-acl时,我会收到很多信息,我想过滤我们的信息或跳过这些信息。基本上我需要:
到目前为止,我尝试过类似的事情:
get-childitem -recurse "$myfolder" | get-acl | select -PSPATH, Group, Access
但是以这种方式,我没有显示全名。
您可以执行以下操作:
$acl = Get-Acl -Path $path
$group = acl.Access | ForEach-Object {$_.identityReference.value}
$Access = acl.Access | ForEach-Object {$_.FileSystemRights}
如果使用Format-Table输出数据,则可以使用-AutoSize属性强制其显示所有信息。
关于您可以使用的完整路径:
get-childitem -recurse "$myfolder" | select FullName
或Messenger选项IMO:
$FullPath = $acl.path -replace ".*::"
第二个选项使用字符串操作来删除所有文本,直到并包括“ ::”]]
编辑:-
这是我使用的完整代码:
$Output = @()
$Path = "C:\SomePath"
$ChildItems = Get-ChildItem -Recurse -Path $Path
foreach($ChildItem in $ChildItems)
{
$FullPath = $ChildItem.FullName
$acl = get-acl $FullPath
$Access = $acl.Access
foreach ($AccessObject in $Access)
{
$Group = $AccessObject.IdentityReference.value
$Rights = $AccessObject.FileSystemRights
$Line = New-Object PSObject
$Line | Add-Member -membertype NoteProperty -name "Path" -Value $FullPath
$Line | Add-Member -membertype NoteProperty -name "Group" -Value $Group
$Line | Add-Member -membertype NoteProperty -name "Rights" -Value $Rights
$Output += $Line
}
}
$Output | Format-Table -AutoSize
尝试此代码。这就是我正在使用的。在Path.txt文件中提供您需要ACL的文件夹列表。
我的偏好(包括删除Microsoft.PowerShell.Core \ FileSystem ::):