• Question

  • Hi ALL need help on powershell script

    Below is the script

    $TargetFolders = Get-Content C:\Input.txt
    $AuditUser = "Everyone"
    $AuditRules = "FullControl"
    $AuditType = "failure"
    $AccessRule = New-Object System.Security.AccessControl.FileSystemAuditRule($AuditUser,$AuditRules,"none","None",$AuditType)
    foreach ($TargetFolder in $TargetFolders)
        $ACL = Get-Acl $TargetFolder
        Write-Host "Processing >",$TargetFolder
        $ACL | Set-Acl $TargetFolder
    Write-Host "Audit Policy applied successfully."

    IT will enable the Folder auditing for everyone for the mention folder

    but i need to add some more

    first it will check if the auditing is not enable then only it will change

    I wanted use if else but not able to add

    Friday, August 11, 2017 12:42 PM

All replies

  • What issue are you having with if/else.

    See: help about_if


    Friday, August 11, 2017 2:31 PM
  • the script is directly enabling the Auditing , But i need

    1. First it will check for Auditing is enable of not if it is enable then no need to do anything give output "Auditing Already Enable"

    2. If the Auditing is not enable then only it will set the auditing... and out put will be "Audit Policy applied successfully"

    Friday, August 11, 2017 2:35 PM
  • Get the audit ACL and test it.


    See: https://msdn.microsoft.com/en-us/library/system.security.accesscontrol.commonobjectsecurity.getauditrules(v=vs.110).aspx


    Friday, August 11, 2017 2:47 PM
  • Hi,
    Just checking in to see if the information provided was helpful. Please let us know if you would like further assistance.

    Best Regards,


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Wednesday, September 6, 2017 7:47 AM