PowerShell Code to check if the SACL of each OU in the AD domain is in canonical order or not.
Also see this blog post.
–
# Clear The Screen Clear-Host # Get The UI Config $uiConfig = (Get-Host).UI.RawUI $uiConfig.ForegroundColor = "Yellow" # Import The Required Module Import-Module ActiveDirectory #Get The RootDSE Info $rootDSE = Get-ADRootDSE # Get List Of OUs In AD Domain $listOfOUsToProcess = Get-ADOrganizationalUnit -Filter * | %{$_.DistinguishedName} # Process Each OU $OUsWithSACLInCanonicalOrder = @() $OUsWithSACLNOTInCanonicalOrder = @() $listOfOUsToProcess | %{ $ou = $_ $ouDrivePath = $("AD:\" + $ou) $aclOU = Get-Acl $ouDrivePath -Audit If ($aclOU.AreAuditRulesCanonical) { $ouObj = "" | Select "List Of OUs That DO Have The SACL In Canonical Order" $ouObj."List Of OUs That DO Have The SACL In Canonical Order" = $ou $OUsWithSACLInCanonicalOrder += $ouObj } If (!$aclOU.AreAuditRulesCanonical) { $ouObj = "" | Select "List Of OUs That DO NOT Have The SACL In Canonical Order" $ouObj."List Of OUs That DO NOT Have The SACL In Canonical Order" = $ou $OUsWithSACLNOTInCanonicalOrder += $ouObj } } $uiConfig.ForegroundColor = "Red" If ($OUsWithSACLNOTInCanonicalOrder.Count -eq 0) { $ouObj = "" | Select "List Of OUs That DO NOT Have The SACL In Canonical Order" $ouObj."List Of OUs That DO NOT Have The SACL In Canonical Order" = "+++ NONE +++" $OUsWithSACLNOTInCanonicalOrder += $ouObj } $OUsWithSACLNOTInCanonicalOrder | FT -Autosize $uiConfig.ForegroundColor = "Green" If ($OUsWithSACLInCanonicalOrder.Count -eq 0) { $ouObj = "" | Select "List Of OUs That DO Have The SACL In Canonical Order" $ouObj."List Of OUs That DO Have The SACL In Canonical Order" = "+++ NONE +++" $OUsWithSACLInCanonicalOrder += $ouObj } $OUsWithSACLInCanonicalOrder | FT -Autosize $uiConfig.ForegroundColor = "Yellow"
–
Figure 1: Checking The Canonical Order Of The SACL On All OUs In The AD Domain Through PowerShell
–
The PowerShell code for this script is included in a ZIP file. The ZIP file can be download from here.
The ZIP file contains all the scripts for the following blogs posts:
- (2014-08-16) PowerShell And DACLs In AD: Adding ACE For Create/Delete Some Object
- (2014-08-18) PowerShell And DACLs In AD: Adding ACE For Read/Write Property On Some Object
- (2014-08-20) PowerShell And DACLs In AD: Adding ACE For Some Extended Right On Some Object
- (2014-08-22) PowerShell And DACLs In AD: Removing ACE For Delete Some Object
- (2014-08-24) PowerShell And DACLs In AD: Removing ACE For Write Property On Some Object
- (2014-08-26) PowerShell And DACLs In AD: Removing ACE For Some Extended Right On Some Object
- (2014-08-28) PowerShell And DACLs In AD: Removing All ACEs On Some Object
- (2014-08-30) PowerShell And SACLs In AD: Adding Auditing Entry For Create/Delete Some Object
- (2014-09-01) PowerShell And SACLs In AD: Adding Auditing Entry For Read/Write Property On Some Object
- (2014-09-03) PowerShell And SACLs In AD: Adding Auditing Entry For Some Extended Right On Some Object
- (2014-09-05) PowerShell And SACLs In AD: Removing Auditing Entry For Create Some Object
- (2014-09-07) PowerShell And SACLs In AD: Removing Auditing Entry For Read Property On Some Object
- (2014-09-09) PowerShell And SACLs In AD: Removing Auditing Entry For Some Extended Right On Some Object
- (2014-09-11) PowerShell And SACLs In AD: Removing All Auditing Entries On Some Object
- (2014-09-13) PowerShell And DACLs In AD: Checking For Correct Canonical Order Of DACL
- (2014-09-15) PowerShell And SACLs In AD: Checking For Correct Canonical Order Of SACL
–
Cheers,
Jorge
———————————————————————————————
* This posting is provided "AS IS" with no warranties and confers no rights!
* Always evaluate/test yourself before using/implementing this!
* DISCLAIMER: https://jorgequestforknowledge.wordpress.com/disclaimer/
———————————————————————————————
############### Jorge’s Quest For Knowledge #############
######### http://JorgeQuestForKnowledge.wordpress.com/ ########
———————————————————————————————