我有以下脚本,
$filteracl = {$_.IdentityReference -match "User" -and ($_.FileSystemRights -band 131241 -or $_.FileSystemRights -band 278)}
$objects = Get-ChildItem "C:\" -Recurse -Force
foreach ($i in $objects)
{
$i.GetAccessControl().Access | Where $filteracl | Select `
@{n="Path";e={$i.fullname}},
@{n="User";e={$_.IdentityReference}},
@{n="Permission";e={$_.FileSystemRights}}
}
但是,路径的输出被截断。我不知道如何解决这个问题。
答案 0 :(得分:0)
尝试Format-Table -Wrap
之类的:
$filteracl = {$_.IdentityReference -match "User" -and ($_.FileSystemRights -band 131241 -or $_.FileSystemRights -band 278)}
$objects = Get-ChildItem "C:\" -Recurse -Force
foreach ($i in $objects)
{
$i.GetAccessControl().Access | Where $filteracl | Select `
@{n="Path";e={$i.fullname}},
@{n="User";e={$_.IdentityReference}},
@{n="Permission";e={$_.FileSystemRights}} |
Format-Table -Wrap
}
由于整个语句处于循环中且Format-Table
显示标题,因此您将看到多个标题。要摆脱这种情况,您可以编辑脚本以将输出存储在Array中,然后在循环完成时最终显示。类似的东西:
$filteracl = {$_.IdentityReference -match "User" -and ($_.FileSystemRights -band 131241 -or $_.FileSystemRights -band 278)}
$objects = Get-ChildItem "C:\" -Recurse -Force
$OutputView = @()
foreach ($i in $objects)
{
$s = $i.GetAccessControl().Access | Where $filteracl
$output = New-Object PSObject
$output | Add-Member -MemberType NoteProperty -Name "Path" -Value $i.fullname
$output | Add-Member -MemberType NoteProperty -Name "User" -Value $s.IdentityReference
$output | Add-Member -MemberType NoteProperty -Name "Permission" -Value $s.FileSystemRights
$OutputView += $output
}
$global:outputView |
Select-Object Path,User,Permission