Powershell 3.0 - Add Group/Username and Enable Full Control permissions

I am needing a script to add in a user. Let's say everyone into the security properties of a directory.

Directory: C:\CBASYNC
User: Everyone
Permissions needed: Full Control

How would I write this out in powershell?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris DentPowerShell DeveloperCommented:
This creates and adds the access control entry.
$acl = Get-Acl "C:\CBASYNC"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule(
Set-Acl "C:\CBASYNC" -AclObject $acl

Open in new window

Chris DentPowerShell DeveloperCommented:
Just a word on the other permission levels.

Get-Acl and Set-Acl do very little for us here, they provide access to the ACL, nothing more. The FileSystemAccessRule is being given strict values.

The access rule is a .NET class: https://msdn.microsoft.com/en-us/library/system.security.accesscontrol.filesystemaccessrule(v=vs.110).aspx

It has strictly defined values.
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule(
    'Everyone',    # An identity (domain\user), or a well known principal (like Everyone)
    'FullControl',    # Access rights
    'ObjectInherit,ContainerInherit',    # Inheritance flags
    'None',    # Propagation flags
    'Allow'    # Type

Open in new window

Each of these has an associate list of constants:

Access rights: https://msdn.microsoft.com/en-us/library/system.security.accesscontrol.filesystemrights(v=vs.110).aspx
Inheritance flags: https://msdn.microsoft.com/en-us/library/system.security.accesscontrol.inheritanceflags(v=vs.110).aspx
Propagation flags: https://msdn.microsoft.com/en-us/library/system.security.accesscontrol.propagationflags(v=vs.110).aspx
Type: https://msdn.microsoft.com/en-us/library/w4ds5h86(v=vs.110).aspx

FullControl is a very broad permission, an easy one to grant.

If you wanted to grant Read only (ReadAndExecute) or Modify you would need to combine those rights with Synchronize. This allows them to appear properly without clicking on the Advanced button in folder properties. For example, this grants the Modify right:
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule(

Open in new window

You can be as granular as you wish with the rights. It can always be written as a comma delimited list as above. PowerShell converts that into numeric values in the background.

These values can be modified such that you can build any possible right you might assign in the GUI.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.