Skip to main content

PowerShell extract shared folder permissions


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

Comments

Post a Comment

Popular posts from this blog

Copy a single file using robocopy

Copy a single file using robocopy from a local folder to a shared folder on the network.
A simple rule of thumb before any disaster strike, don't interchange the source and the destination.

If source and destination is mistakenly reverse, files might get overwritten. To avoid any loss of data do a test with a dummy file to ensure things work perfectly.
Robocopy [source][destination]   [file to be copied]
robocopy c:\local_c_folder  \\PC_network\shared_folder   file_to_be_copied_xx.txt
The command will be completed successfully provided the network access right has no issues.

Robocopy works quite good on large files. A simple copy or xcopy command will also work but the speed might vary.

Robocopy is free it can be accessed from command line. No need to install the resource kit tool if the operating system is Windows 7 or newer version.

Copy files with selected file extension using PowerShell and Robocopy:

$extension = ('.pdf', '.jpg', '.txt')
gci d:\WorkFolde…

WMIC get computer name

WMIC get computer model, manufacturer, computer name and  username.
WMIC is a command-line tool and that can generate information about computer model, its manufacturer, its username and other informations depending on the parameters provided.
Why would you need a command line tool if there’s a GUI to check?
If you have 20 or 100 computers, or even more. It’s quite a big task just checking the GUI to check the computer model and username.
If you have remote computers, you need to delegate someone in the remote office or location to check.
Or you can just write a batch file or script to automate the task.
Here’s the code below on how get computer model, manufacturer and the username.
Open an elevated command prompt and type:
wmic computersystem get "Model","Manufacturer", "Name", "UserName"
Just copy and paste the code above, the word “computersystem” does not need to be change to a computer name.
A sample output below will be generated if the co…