NTFS许可以及修改日期 [英] NTFS permission with modify date

查看:102
本文介绍了NTFS许可以及修改日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将服务器上的文件夹和子文件夹的NTFS权限导出到CSV。
它应该显示具有权限的用户和组以及文件夹的上次修改日期。

I want to export NTFS permissions of folders and subfolders on the server to a CSV. It should show users and groups with permissions and last modify date of folders.

这是到目前为止的内容,但不显示修改

Here is what I have got so far, but it doesn't show modify date and it exports disorganize.

Get-ChildItem C:\FILES\ -Recurse | where {$_.PSIsContainer} |
  Get-Acl | % {
    $path = $_.Path
    $_.Access | % {
      New-Object PSObject -Property @{
        Folder      = $path.Replace("Microsoft.PowerShell.Core\FileSystem::", "")
        Access      = $_.FileSystemRights
        Control     = $_.AccessControlType
        User        = $_.IdentityReference
        Inheritance = $_.IsInherited
      }
    }
  } | ? {$_.Inheritance} | Export-Csv C:\Users\test_dump.csv -Force


推荐答案

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.

这篇关于NTFS许可以及修改日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆