powershell - Get shared folder permissions
问题描述
Im quite new with powershell and I need to do a shared folders permission report. I've the following code:$path = \\server\shared_folder
dir $path | where { $_.PsIsContainer } | % { $path1 = $_.fullname; Get-Acl $_.Fullname | % { $_.access | Add-Member -MemberType NoteProperty '.\Application Data' -Value $path1 -passthru }} | Export-Csv $reportpath
But the output is:
\\server\shared_folder\folder1;FileSystemRights;AccessControlType;IsInherited;InheritanceFlags;PropagationFlags
\\server\shared_folder\folder2;FileSystemRights;AccessControlType;IsInherited;InheritanceFlags;PropagationFlags
I need the following output:
\\server\shared_folder;FileSystemRights;AccessControlType;IsInherited;InheritanceFlags;PropagationFlags
Why is doing the "dir" recursiveley if I do not specify it? If I am specifying where im telling to do so?
解决方案
要获得您要求的确切答案:
$path = "\\server\shared_folder"
dir $path | where { $_.PsIsContainer } | % { $path1 = $_.Root; Get-Acl $_.Fullname | % { $_.access | Add-Member -MemberType NoteProperty '.\Application Data' -Value $path1 -passthru }} | Export-Csv $reportpath
注意 ForEach-Object (%) 后面的“$_.Root”。但在我看来,以下更好,因为这样您可以在“.\Application Data”下看到文件夹名称:
$path = "\\server\shared_folder"
dir $path | where { $_.PsIsContainer } | % { $path1 = $_.Name; Get-Acl $_.Fullname | % { $_.access | Add-Member -MemberType NoteProperty '.\Application Data' -Value $path1 -passthru }} | Export-Csv $reportpath
希望这会有所帮助,因为您的问题不是很清楚 imo。
推荐阅读
- python - 慢功能动画脚本
- oracle11g - oracle DB 11g 中的数据库表分区
- aws-lambda - AWS AppSync 使用存在检查解析器将多个子项添加到一个父属性中
- numpy - NumPy 广播是关联的吗?
- typescript - 覆盖抽象方法 TypeScript?
- android - Flutter:如何使用 DropDownMenuItems 导航到新屏幕
- angular - 对象已修改,但数组未修改
- android - Android 应用程序崩溃异常
- ios - 洛蒂-iOS。应用显示来自网络的 JSON 动画,但不是我在 After Effects 中渲染的 JSON
- javascript - Chunk.entrypoints:改用 Chunk.addGroup