PowerShell – Get Permissions on Folder and Subfolders

PowerShell - get Permissions on folder and subfolders

To understand how to get permissions on a folder and subfolder in PowerShell, you must first understand what folder and subfolder permissions are. A folder’s permissions establish who can access and modify files and folders. A subfolder permission is a permission set for a folder containing other folders. In general, permissions set on a folder will propagate to any subfolders unless you specify otherwise.

Permissions can be set for users or groups, such as Administrators, Users, and Guests. The permissions include Full Control, Modify, Read & Execute, List Folder Contents, Read, and Write. To proceed further, knowing the folders and sub-folders in the current directory is crucial. For instance, the current working directory for this article is located at C:\Test.

C:\Test consists of two text files (File1.txt and File2.txt) and folders (FolderG and FolderH). The items in each folder include the following:

  • C:\Test\FolderG – It contains two text files ( File1.txtand File6.txt).
  • C:\Test\FolderH – It has one text file (File6.txt).

So now you know the directories’ details, let’s continue learning to get permission.

Using Get-Acl Command

Use the Get-Acl command to get permissions on the specified folder in PowerShell. Get-Acl cmdlet is used to get Access control List(ACL) for files and folders.

In the above code, the Get-Acl cmdlet was used to get the Access Control List (ACL) for a file or folder containing the permissions set for that file or folder.

If you notice, you see here after FullControl as it doesn’t show you complete text.

To get the complete text, use Format-table cmdlet with -wrap option.

Here is an example:

Get Permissions on current working directory

To get permissions in current working directory, simply use get-acl cmdlet without any parameters. It will give you Access control list for current working directory.

Using Get-ChildItem with Get-Acl Cmdlet

Use Get-Childitem with the Get-Acl cmdlet to get permissions on folders and subfolders in PowerShell.

In the above code, TheGet-ChildItem cmdlet retrieves a collection of child items (files and directories) in the specified folder. The -Path parameter specifies the path to the folder to search, which is C:\Test. The -Recurse parameter indicates that the command should also search recursively through all subfolders.

The | pipeline operator takes the output from the Get-ChildItem command and sends it as input to the next command in the pipeline. And theGet-Aclcmdlet retrieves the Access Control List (ACL) for the input object, each file and directory returned by the Get-ChildItem command.

This command’s output shows the permissions set for each file and directory, including the names of users and groups that have access and the level of access they have.

Considering the above solutions, understanding folder and subfolder permissions are essential for setting and managing permissions effectively. Using the Get-Acl and Get-ChildItem, you can easily get and export permissions for folders and subfolders in PowerShell. With these examples, you can confidently start managing folder and subfolder permissions.

That’s all about how get permission on folders and subfolers in PowerShell.

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *