Skip to content

Instantly share code, notes, and snippets.

@sito74
Created December 6, 2021 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sito74/33fc655cdb50c6c7f9028654bf624d8b to your computer and use it in GitHub Desktop.
Save sito74/33fc655cdb50c6c7f9028654bf624d8b to your computer and use it in GitHub Desktop.
param($TargetPath= "\\fileserver.contoso.local\share",
$Directory = $true)
Measure-Command{
if($Directory){
$Items=Get-ChildItem $TargetPath -Recurse -Directory
$Ancestor_output = (Join-Path $TargetPath Ancestor.csv)
$error_output = (Join-Path $TargetPath Get-Acl_dir_Error.txt)
}else{
$Items=Get-ChildItem $TargetPath -Recurse
$access_output = (Join-Path $TargetPath FileAccessRights.csv)
$error_output = (Join-Path $TargetPath Get-Acl_file_Error.txt)
}#end of if($Directory)
$error.Clear()
$Ancestor = @()
for($i=0;$i -lt $Items.count;$i++){
$Item = $Items[$i].Fullname
try{
$Acls = Get-Acl $Item
$Access =$Acls.Access[0]
foreach($Access in $Acls.Access){
if (-not $Access.IsInherited){
$Row = "" | Select Path,IdentityReference,FileSystemRights,AccessControlType
$Row.Path =(Convert-Path $Acls.Path)
$Row.IdentityReference = $Access.IdentityReference
$Row.FileSystemRights = $Access.FileSystemRights
$Row.AccessControlType = $Access.AccessControlType
$Ancestor += $Row
}
}
}catch{
$Item >> $error_output
$Error[0] >> $error_output
}
} #End of for($i=0;$i -lt $Items.count;$i++)
$Ancestor |Export-Csv $Ancestor_output -Encoding Default -NoTypeInformation
} #End of Measure-Command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment