Search code examples
powershellcsvnetwork-shares

PowerShell Shares ACL List


I have this script that goes into each file of one shared drive and lists the ACLs, but I don't want it to go so far because there are millions of files and it will never finish (ran for over a day and got a csv file over 6 GB).

I tried using get-childitem *** but it doesn't seem to work. Any help would be greatly appreciated. Ideally, just 2 levels deep would be nice. 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"

Solution

  • you can have it leave out the files themselves and only get the folders with something like this...

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

    That should only get the folders or things that "IsContainer"