title: Unable to write a Powershell function for giving folder permissions to a user
body: <p>I tried writing this function but it did not work. However, when I exclude the body from the function, it does start working. I need a function which will add a user and give full permission to the folder. Any help will be appreciated.</p>
  
  <pre><code>function Grant-userFullRights {            
   Param(
    [string]$UserName,
    [string]$Files
  )       
  $Acl = Get-Acl $Files
  $Ar = New-Object System.Security.AccessControl.FileSystemAccessRule($UserName, "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")
  $Acl.SetAccessRule($Ar)
  Set-Acl $Files $Acl
  }
  
  Grant-userFullRights "CHAD\sv_CS_CH", "G:\testing"
  </code></pre>