[英]Error Trying to get-acl from child folders in script
I have been doing this code lately trying to get only everyones and authenticated users from the ACL in shared folders. 我最近一直在执行此代码,试图仅从共享文件夹中的ACL中获取所有人和经过身份验证的用户。
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 该脚本确实获取了共享并对其进行了迭代,但是我无法从父文件夹或其子文件夹中获取ACL。
And also, I would like to know how to export not using export-csv
iterating over every share instead over every server. 而且,我想知道如何不使用对每个共享而是对每个服务器进行迭代的
export-csv
进行export-csv
。
Tried with -Depth
Parameter, changed parameter get-childitem
to get-item
. 尝试使用
-Depth
参数,将参数get-childitem
更改为get-item
。
The only way it worked is to leave open the where-object comenting #-like 'Everyone' -or $_.IdentityReference -like 'NT Authority\\Authenticated Users' } |
它唯一有效的方法是打开
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 预期导出到csv文件,但我有
Get-Acl : Cannot Find Path 'XXXX' because it does not exists + Get-Acl $Dir
Get-Acl:无法找到路径“ XXXX”,因为它不存在+ 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 {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.