@@ -11164,7 +11164,7 @@ The raw DirectoryServices.SearchResult object, if -Raw is enabled.
11164
11164
$ObjectOUs = @()
11165
11165
$ObjectOUs += $ObjectDN.split(',') | ForEach-Object {
11166
11166
if($_.startswith('OU=')) {
11167
- $ObjectDN.SubString($ObjectDN.IndexOf($_ ))
11167
+ $ObjectDN.SubString($ObjectDN.IndexOf("$($_)," ))
11168
11168
}
11169
11169
}
11170
11170
Write-Verbose "[Get-DomainGPO] object OUs: $ObjectOUs"
@@ -11174,13 +11174,28 @@ The raw DirectoryServices.SearchResult object, if -Raw is enabled.
11174
11174
$SearcherArguments.Remove('Properties')
11175
11175
$InheritanceDisabled = $False
11176
11176
ForEach($ObjectOU in $ObjectOUs) {
11177
- if ($InheritanceDisabled) { break }
11178
11177
$SearcherArguments['Identity'] = $ObjectOU
11179
11178
$GPOAdsPaths += Get-DomainOU @SearcherArguments | ForEach-Object {
11180
11179
# extract any GPO links for this particular OU the computer is a part of
11181
- $_.gplink.split('][') | ForEach-Object {
11182
- if ($_.startswith('LDAP')) {
11183
- $_.split(';')[0]
11180
+ if ($_.gplink) {
11181
+ $_.gplink.split('][') | ForEach-Object {
11182
+ if ($_.startswith('LDAP')) {
11183
+ $Parts = $_.split(';')
11184
+ $GpoDN = $Parts[0]
11185
+ $Enforced = $Parts[1]
11186
+
11187
+ if ($InheritanceDisabled) {
11188
+ # if inheritance has already been disabled and this GPO is set as "enforced"
11189
+ # then add it, otherwise ignore it
11190
+ if ($Enforced -eq 2) {
11191
+ $GpoDN
11192
+ }
11193
+ }
11194
+ else {
11195
+ # inheritance not marked as disabled yet
11196
+ $GpoDN
11197
+ }
11198
+ }
11184
11199
}
11185
11200
}
11186
11201
0 commit comments