I have been doing this code lately trying to get only everyones and authenticated users from the ACL in shared folders.
The script does get the shares and iterate over them, but I'm unable to get the ACL's from parent folder nor its childs
And also, I would like to know how to export not using export-csv
iterating over every share instead over every server.
Tried with -Depth
Parameter, changed parameter get-childitem
to get-item
.
The only way it worked is to leave open the where-object comenting #-like 'Everyone' -or $_.IdentityReference -like 'NT Authority\\Authenticated Users' } |
$Server="Server"
$shares = gwmi win32_Share -ComputerName $Server |
Where-Object {$_.type -eq '0'} |
Where {$_.name -notlike "*$*"} | Select-Object -ExpandProperty Name
$Shares
foreach ($share in $shares){
$root = "\\$Server\$share"
$csv = "C:\temp\$Server-$share.csv"
Remove-Item $csv
New-Item $csv
Get-ChildItem -literalPath $root -Recurse -directory |
ForEach-Object {
$dir = $_
##Test-Path $dir}}
Get-Acl $dir | Select-Object -Expand Access |
Where-Object { $_.IdentityReference }|#-like 'Everyone' -or $_.IdentityReference -like 'NT Authority\Authenticated Users' } |
ForEach-Object {
New-Object PSObject -Property @{
Folder = $dir.FullName
Access = $_.FileSystemRights
Control = $_.AccessControlType
User = $_.IdentityReference
Inheritance = $_.IsInherited
LastModified = $dir.LastWriteTime
}
}
} | Export-Csv $csv -Force
}
Expected An export to a csv file but i have
Get-Acl : Cannot Find Path 'XXXX' because it does not exists + Get-Acl $Dir
You need to parenthesise your conditionals for a start:
Get-Acl $dir | Select-Object -Expand Access |
Where-Object { ($_.IdentityReference -like 'Everyone') -or ($_.IdentityReference -like 'NT Authority\Authenticated Users') } |
ForEach-Object {
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.