#-------------[deklarations]--------------------------
#source
#logs
#$successLog='\\host\shares\!scripts\!logs\done.LOG'
#$errorLog='\\host\shares\!scripts\!logs\error.LOG'
#$unreachableLog='\\host\shares\!scripts\!logs\unreachable.LOG'
$reportLog='\\host\shares\!scripts\!reports\dirsACL.csv'
#params
$dirToCheck='\\host\shares\*\*'
$header = 'path,dir,acl,user,isEnable'
#-------------[functions]--------------------------
Add-Content -Value $header -Path $reportLog
$dirs = dir $dirToCheck | where {$_.PsIsContainer -eq $true}
foreach($dir in $dirs) {
$acls = (Get-Acl $dir.FullName).Access
$dirName = $dir.FullName.Split("\")[5]
foreach($acl in $acls) {
$user = Get-ADUser $aclIdentityRefernce | ? {$_.UserPrincipalName -ne $null} | Select -ExpandProperty UserPrincipalName
$username = $user.Split("@")[0]
$user = Get-ADUser -Filter "UserPrincipalName -Eq '$user'"
$samAccountName - $user.SamAccountName.ToString()
$output = $dir.Fullname + "," + dirName + "," + $acl.AccessControlType + "," + $username + "," + $user.Enabled
$output
Add-Content - Value $output -Path $reportLog
}
}
#-------------krolaki.eu--------------------------