Reputation: 73
I am writing a PowerShell script, and I want part of that to list who has Full Control to a given folder. I just cannot find any examples of how to do this.
As a test, I have a variable called $acl that points to C:\TestFolder. My command is:
$acl.access | ForEach-Object { $_.FileSystemRights | Where-Object { $_ -eq 'FullControl' } }
This displays:
FullControl
FullControl
FullControl
as there is my domain account, BUILTIN\Administrators and NT AUTHORITY\SYSTEM. However, I want it to display:
<my domain account>
BUILTIN\Administrators
NT AUTHORITY\SYSTEM
Eventually I will run this on network folders on my company's NAS, and there could be 10s of people with Full Control. My ultimate goal is to evaluate the list to see if any of these accounts are a member of a specific AD group.
Please could someone point me in the right direction?
Thanks in advance,
Rob.
Upvotes: 3
Views: 1239
Reputation: 2590
Try changing your command query slightly to the following:
$acl.access | Where-Object { $_.FileSystemRights -eq 'FullControl' } | Select-Object { $_.IdentityReference }
Edited per suggestion below.
Upvotes: 3