title: Set-Acl : Attempted to perform an unauthorized operation while using Addaudit Rule
body: <p>I am trying to run Powershell script to set Audit Rule on C:\Windows\security folder on my Windows 2008 box.</p>
  
  <p>Below is the script:</p>
  
  <pre><code>$FileDirList = ("C:\Windows\security")
  
  $AccountName     = New-Object System.Security.Principal.NTAccount("Everyone") 
  $FileSystemRight = [System.Security.AccessControl.FileSystemRights]::FullControl
  $AuditFlag       = [System.Security.AccessControl.AuditFlags]::Failure
  $InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::None
  $PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None
  
  #
  #write-OSPBOSbuildLog  "Applying Audit Setting"
  #     
  
  foreach ($FileDirName in $FileDirList) {   
      #write-OSPBOSbuildLog  "&gt;&gt;&gt;&gt;&gt;  Appying audit setting to $FileDirName"
  
      $AuditRule = New-Object System.Security.AccessControl.FileSystemAuditRule $AccountName, $FileSystemRight, $InheritanceFlag, $PropagationFlag, $AuditFlag 
  
      $objACL = Get-ACL $FileDirname 
  
      $objACL.AddAuditRule($AuditRule)
  
      Set-ACL $FileDirname $objACL
  } 
  </code></pre>
  
  <p>But I am getting error as shown below:</p>
  
  <blockquote>
  <pre><code>Set-Acl : Attempted to perform an unauthorized operation.
  At C:\IBM\File-Perm.ps1:22 char:12
  +     Set-ACL &lt;&lt;&lt;&lt;  $FileDirname $objACL
      + CategoryInfo          : PermissionDenied: (C:\Windows:String) [Set-Acl], UnauthorizedAccessException
      + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.SetAclCommand
  </code></pre>
  </blockquote>
  
  <p>Please help me understand what changes I need to do?</p>
  
  <p>Thanks in Advance!!</p>