powershell을 사용하여 Active Directory 조직 단위에 감사 규칙 추가

powershell을 사용하여 Active Directory 조직 단위에 감사 규칙 추가

아래 powershell 스크립트에서는 특정 OU에 대한 Active Directory 감사 규칙을 수집하고, 오류에 대한 감사 규칙이 있는지 확인하고, 존재하지 않는 경우 오류 감사 규칙을 추가합니다. 실패 규칙을 추가하는 마지막 단계까지 모든 것이 작동합니다. 오류 메시지는 없지만 새 규칙이 Active Directory에 나타나지 않습니다.

#find the needed OU
Import-Module activedirectory
Set-Location ad:
dir

#get an acl object based for the OU
$acl = Get-Acl -Path "DC=something,DC=somethingElse" -Audit
$auditRules = $acl.GetAuditRules(1,1,[System.Security.Principal.SecurityIdentifier])
$foundFailRule = $false
foreach ($rule in $auditRules) {
    if ($rule.AuditFlags -ieq "Failure") {
        $foundFailRule = $true
        break
    }
}
if ($foundFailRule -eq $true) {
    Write-Host "Found fail rule.  No action needed."
}
else {
    #find the IdentityReference from the first audit rule entry in the OU
    $identityReference = $auditRules[0].IdentityReference
    $activeDirectoryRights = "GenericAll"
    $auditFlags = "Failure"
    $failAuditRule = New-Object System.DirectoryServices.ActiveDirectoryAuditRule $identityReference, $activeDirectoryRights, $auditFlags
    $acl.AddAuditRule($failAuditRule)
}

이것이 중요한지 확실하지 않지만 OU에 대한 기본 감사 규칙에서 때로는 ObjectType 및 InheritedObjectType이 모두 0인 문자열이고 다른 경우에는 0이 아닌 일부 데이터가 포함되어 있다는 것을 알았습니다. 위의 생성자 메서드를 사용하면 해당 속성의 기본값은 모두 0입니다.

AddAuditRule 메서드가 OU에서 새 규칙을 생성하지 않는 이유를 아시나요? 오류가 없기 때문에 규칙을 추가하는 중일 수도 있지만 Active Directory의 예상치 못한 위치에 채워지고 있습니까?

관련 정보