PowerShell共享ACL列表

时间:2015-07-14 16:05:24

标签: powershell csv network-shares

我有这个脚本进入一个共享驱动器的每个文件并列出了ACL,但我不希望它到目前为止,因为有数百万个文件,它永远不会完成(运行超过一个一天,得到超过6 GB的csv文件)。

我尝试使用get-childitem ***但它似乎没有用。任何帮助将不胜感激。理想情况下,只有2级深度会很好。 THX

$ErrorActionPreference = "Continue" 
$strComputer = $env:ComputerName 
$colDrives = Get-PSDrive -PSProvider Filesystem 
#IF ($DriveLetter -eq "N:\") 

    $StartPath = "N:" 
    Get-ChildItem $StartPath\*\*\ -Recurse | 
    ForEach { 
      $FullPath = Get-Item -LiteralPath (Get-Item -LiteralPath $_.PSPath) 
      (Get-Item -LiteralPath $FullPath).GetAccessControl() | 
      Select * -Expand Access | 
      Select @{N='Server Name';E={$strComputer}}, 
             @{N='Full Path';E={$FullPath}}, 
             @{N='Type';E={If($FullPath.PSIsContainer -eq $True) {'D'} Else {'F'}}}, 
             @{N='Owner';E={$_.Owner}}, 
             @{N='Trustee';E={$_.IdentityReference}}, 
             @{N='Inherited';E={$_.IsInherited}}, 
             @{N='Inheritance Flags';E={$_.InheritanceFlags}}, 
             @{N='Ace Flags';E={$_.PropagationFlags}}, 
             @{N='Ace Type';E={$_.AccessControlType}}, 
             @{N='Access Masks';E={$_.FileSystemRights}} } | 
      Export-CSV -NoTypeInformation –Path "C:\stuff\NDriveShares.csv"

1 个答案:

答案 0 :(得分:1)

你可以让它自己遗漏文件,只得到这样的文件夹......

Get-ChildItem -Recurse | ?{ $_.PSIsContainer }

那应该只获取“IsContainer”

的文件夹或内容