using powershell to set file audit settings

Welcome Forums General PowerShell Q&A using powershell to set file audit settings

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
6 days, 12 hours ago.

  • Author
    Posts
  • #128715

    Participant
    Points: 14
    Rank: Member

    from my understanding, I can use set-acl to add file/folder audit setting

    can I somehow feed that command a text file that contains a list of file names that need the exact same audit settings?

    For every new computer we set up, I need to change audit settings on 75-100 files with the exact same settings. We do this manually but would really like to script it.

    The only code I found online is the following but it just copies the audit settings from one folder to another:

    get-acl c:\users\administrator\desktop\test2\ -Audit| set-acl c:\users\administrator\desktop\test\

  • #128723

    Participant
    Points: 25
    Rank: Member

    A simple loop should do it. Using a an existing ACL is easier than building one, which can be a bit fiddly.

    $files = Get-Content c:\temp\fileList.txt
    
    $acl = Get-ACL c:\myAuditTemplate\ -Audit
    
    foreach ($file in $files) {
    
      Set-Acl -path $file -AclObject $acl
    
    }
    
    
    • #128732

      Participant
      Points: 14
      Rank: Member

      thanks.

      I'll test that out and see if I run into any issues.

You must be logged in to reply to this topic.