From b6fc7a676b0c5b4cdd15b22b2b2e0f642c50f1ef Mon Sep 17 00:00:00 2001 From: Przemyslaw Klys Date: Sun, 17 Oct 2021 14:55:59 +0200 Subject: [PATCH] Internal function --- Private/Get-GPOBlockedInheritance.ps1 | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Private/Get-GPOBlockedInheritance.ps1 diff --git a/Private/Get-GPOBlockedInheritance.ps1 b/Private/Get-GPOBlockedInheritance.ps1 new file mode 100644 index 0000000..664e587 --- /dev/null +++ b/Private/Get-GPOBlockedInheritance.ps1 @@ -0,0 +1,30 @@ +function Get-GPOBlockedInheritance { + [cmdletBinding()] + param( + [string] $Filter = '*', + + [alias('ForestName')][string] $Forest, + [string[]] $ExcludeDomains, + [alias('Domain', 'Domains')][string[]] $IncludeDomains, + [switch] $AsHashTable, + [System.Collections.IDictionary] $ExtendedForestInformation + ) + $OUCache = [ordered] @{} + + $ForestInformation = Get-WinADForestDetails -Extended -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ExtendedForestInformation + + foreach ($Domain in $ForestInformation.Domains) { + $OrganizationalUnits = Get-ADOrganizationalUnit -Filter $Filter -Properties gpOptions, canonicalName -Server $ForestInformation['QueryServers'][$Domain]['HostName'][0] #-SearchScope Subtree + foreach ($OU in $OrganizationalUnits) { + $OUCache[$OU.DistinguishedName] = [PSCustomObject] @{ + DistinguishedName = $OU.DistinguishedName + BlockedInheritance = if ($OU.gpOptions -eq 1) { $true } else { $false } # blocked inheritance + } + } + } + if ($AsHashTable) { + $OUCache + } else { + $OUCache.Values + } +}