Add Permissions on Files and Folders using PowerShell

Seems very simple, but I had to puzzle a little to get it working,

here’s a small function I came up with, maybe it will save you some time,

it will Add  permissions, not replace the ACL.

 

Function GrantFullControl ($File)

{

 $acl = $file.GetAccessControl()

$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule (“Administrators”,”FullControl”,”Allow”)

$acl.AddAccessRule($accessrule)

$file.SetAccessControl($acl)

}

So you can call it like this:

$MyFile = Get-ChildItem “Myfile.txt”

GrantFullControl $MyFile

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s