-
-
Save sito74/33fc655cdb50c6c7f9028654bf624d8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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