At our company file server we used to have loose permissions several years ago. Meaning, there are folders where users tend to have full permission. This is a bad thing (user playing with rights, locking out the system (and the backup with it) and only giving themselves access.
My goal:
Scan the fileserver folder by folder (files would be too much) and output
- folder full path
- Security Identity Reference
if someone has fullaccess besides domain admins or system.
The output would be fine as:
Path, ACL E:\share\projectfolder, Domain\10JohnDoe E:\share\commonfolder, Domain\Everyone ...
This is what I have, but it is not nearly enough:
##define variable
$path = "E:\Share"
## begin script
foreach ($file in Get-Childitem $path -Recurse -Directory) {
if (Get-Acl $file.FullName |
select -ExpandProperty Access |
where {$_.IdentityReference -notlike "AT\Domain Admins" -and
$_.IdentityReference -notlike "NT AUTHORITY\SYSTEM" -and
$_.AccessControlType -like "Allow" -and
$_.FileSystemRights -like "FullControl"}
) {
Write-Host $file.FullName >> e:\check_acl.txt
Get-Acl $file.FullName |
select -ExpandProperty Access |
where {$_.IdentityReference -notlike "AT\Domain Admins" -and
$_.IdentityReference -notlike "NT AUTHORITY\SYSTEM" -and
$_.AccessControlType -like "Allow" -and
$_.FileSystemRights -like "FullControl"
} >> e:\check_acl.txt
}
}
But I guess, I cannot get the output (into file!) like that.