How to extract list of shared folders permissions?
If the path of shared folder and its sub folders are not too long, it will be smooth and easy to get the security permissions.
If the paths are quite long, then it will be a challenge.
Robocopy.exe a command line tool, that is able to list folder and sub folders even the path are too long.
Used the robocopy script from this link, to list all the files, folder and sub folders and save to a text file.
But the robocopy output, will have a very detailed output that includes complete file names, the number of files on each folder and other details.
To list the shared folder security permissions on PowerShell using the Get-Acl cmdlet; what is needed is just the path to the folder.
So from the text file of robocopy output, need to extract the path directory for all the folders.
Using the PowerShell script from this link (http://powershell.com/cs/forums/t/12206.aspx):
=====================
#from this link
#http://powershell.com/cs/forums/t/12206.aspx
$pathToFile="d:\robocopy_folder_list.txt"
$flag=0
Get-Content $pathToFile |
foreach {
Switch -Wildcard ($_){
"*New Dir*" {$flag=1}
"*New File*" {$flag=0}
}
if ($flag -eq 1){
Out-File d:\fxresults.txt -InputObject $_ -Append
}
}
=====================
Script above will extract path directories.
The extracted output will be like this:
New Dir 63 c:\shared\
New Dir 34 c:\shared\1\IconRestorer\Languages\
List can go on up to thousands of lines depend on how many folders on the list.
The "New Dir and the number" is not needed, and it will be tedious to delete it line by line.
To clean up this, I did it manually with the aid of Notepad++, not so hard.
I just open the text file using Notepad++ and used the Alt+Shift method to select the two columns and use page down to delete.
After cleaning up the text file, save it to another file name and what should remain is just the path.
c:\shared\
c:\shared\1\IconRestorer\Languages\
To get the shared folder permissions for all the folders.
Open the text file using PowerShell and use Get-ACL cmdlet.
Here's the simple code snippet to list the security permissions for all the sub folders.
=====================================
$pathToFile = "d:\extracted_directory_path_results.txt"
$xLines = Get-Content $pathToFile
ForEach ($Line In $xLines)
{
$xstr = $Line.ToString()
#Write-Host ($xstr.Trim())
#need to trim the string or Get-Acl will throw an error
#this line will just display the output
Get-ACL($xstr.Trim()) | Format-list
#will save the result to a text file
#Get-ACL ($xstr.Trim()) | Format-list | out-file d:\Folder_Security_List.txt -Append
}
=====================================
It's a 3 step method that cost no money, but it does the job for listing security permissions for hundreds or thousands of folder and sub folders within a few minutes.
The PowerShell script should be read with administrative privileges, or else it will not be able to get the security permissions.
If there's a shorter way for doing this, please share it.
Cheers!!
====================
Free Android App with No Ads.
Heaven's Dew Fall
https://play.google.com/store/apps/details?id=soulrefresh.beautiful.prayer
Android Catholic Rosary App - Guide
https://play.google.com/store/apps/details?id=com.myrosaryapp&hl=en-GB
Educational App for Android Kids:
https://play.google.com/store/apps/details?id=com.letsmultiply
try to use long path tool.
ReplyDelete