Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell using get-acl to return only user/groupnames?

Tags:

powershell

acl

I need to show all the domain\username|groupname of everyone who is allowed access to a particular folder to feed into another command (I'll be removing access for all users and setting new user rights), is there anyway to format a list that returns just this parameter? I know it's probably some combination of select-object and format-list, but I'm not sure exactly what I'm looking for.

like image 206
Bob Fishel Avatar asked Oct 28 '25 05:10

Bob Fishel


1 Answers

You can retrieve that from the IdentityReference property of the Access property of get-acl. Here's an example from my user folder:

PS C:\> $users = @((get-acl 'C:\users\myUser').Access | 
                 Select-Object -ExpandProperty IdentityReference)
PS C:\> $users

Value
-----
NT AUTHORITY\SYSTEM
BUILTIN\Administrators
DOMAIN\myUser

The objects returned in the collection are of the type NTAccount.

like image 116
Anthony Neace Avatar answered Oct 31 '25 03:10

Anthony Neace