title: Setting permissions on a windows fileshare
body: <p>I have the following code which is supposed to go through the folders in the fileshare and turn whatever permissions there are into read permissions. However, there is a problem: it doesn't replace the permissions already there it merely adds to them. Secondly, if the folder has not got inherited permissions it gives an error saying</p>
  
  <blockquote>
    <p>Set-Acl : The process does not possess the 'SeSecurityPrivilege' privilege which is required for this operation.</p>
  </blockquote>
  
  <p>I have checked the permissions and I have full control on them</p>
  
  <pre><code>function NotMigrated($SiteURL, $Folder) {
      try {
          $SiteString=[String]$SiteURL
          $pos = $SiteString.LastIndexOf("/")         
          $Site = $SiteString.Substring($pos+1)
          $parent=((get-item $Folder ).parent).Fullname
  
          $AllFolders = Get-ChildItem -Recurse -Path $Folder |? {$_.psIsContainer -eq $True}
          $FilesInRoot = Get-ChildItem -Path $Folder | ? {$_.psIsContainer -eq $False}
          $acl= get-acl $Folder
          foreach ($usr in $acl.access) {
              $acl.RemoveAccessRule($usr)
              $rule = New-Object System.Security.AccessControl.FileSystemAccessRule($usr.IdentityReference,"Read","none","none","Allow")
              $Acl.AddAccessRule($rule)
          }
          $acl | Set-Acl
       } catch { continue }
  
      #Loop through all folders (recursive) that exist within the folder supplied by the operator
      foreach ($CurrentFolder in $AllFolders) {
          #Set the FolderRelativePath by removing the path of the folder supplied by the operator from the fullname of the folder
          $FolderRelativePath = ($CurrentFolder.FullName).Substring($Folder.Length)
          $FileSource = $Folder + $FolderRelativePath
  
          try {
              $acl= get-acl $FileSource
              foreach ($usr in $acl.access) {
                  $acl.RemoveAccessRule($usr)
                  $rule = New-Object System.Security.AccessControl.FileSystemAccessRule($usr.IdentityReference,"Read","none","none","Allow")
                  $acl.AddAccessRule($rule)
              }
              $acl | Set-Acl 
          } catch { continue }
  
          #For each file in the source folder being evaluated, call the UploadFile function to upload the file to the appropriate location
      }
  }
  </code></pre>