首页 > 解决方案 > 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?

标签: powershell

解决方案


要获得您要求的确切答案:

$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。


推荐阅读